[Aptitude-svn-commit] r3421 - in branches/aptitude-0.3/aptitude: . src/vscreen
Daniel Burrows
dburrows@costa.debian.org
Sat, 25 Jun 2005 16:13:37 +0000
Author: dburrows
Date: Sat Jun 25 16:13:34 2005
New Revision: 3421
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc
branches/aptitude-0.3/aptitude/src/vscreen/curses++.h
Log:
Add preliminary code to output wide-character strings.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Sat Jun 25 16:13:34 2005
@@ -1,5 +1,10 @@
2005-06-25 Daniel Burrows <dburrows@debian.org>
+ * src/vscreen/curses++.cc, src/vscreen/curses++.h:
+
+ Add a preliminary, very hacky, routine to output wide-character
+ strings.
+
* src/vscreen/Makefile.am, src/vscreen/transcode.cc, src/vscreen/transcode.h:
Add support code to wrap iconv in a simpler (less efficient)
Modified: branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc Sat Jun 25 16:13:34 2005
@@ -89,6 +89,15 @@
*i=st.apply_to(*i);
}
+int wchstring::width() const
+{
+ int rval=0;
+ for(const_iterator i=begin(); i!=end(); ++i)
+ rval+=wcwidth(i->ch);
+
+ return rval;
+}
+
int char_traits<chtype>::compare(const chtype *s1,
const chtype *s2,
size_t n)
@@ -311,3 +320,54 @@
mvaddnstr(height-1,0,s.c_str(),width);
}
+
+int cwindow::addstr(const wchstring &str)
+{
+ return addnstr(str, str.size());
+}
+
+int cwindow::addnstr(const wchstring &str, size_t n)
+{
+ int rval=OK;
+
+ for(string::size_type i=0; i<n && i<str.size(); ++i)
+ {
+ // Construct a cchar_t from the single character at the head of
+ // the string. The weird intermediate single-character string
+ // exists to work around the vagueness of the setcchar
+ // semantics.
+
+
+ cchar_t wch;
+ wchar_t dummy[2];
+
+ dummy[0]=str[i].ch;
+ dummy[1]=L'\0';
+
+ // How can I notify the user of errors?
+ if(setcchar(&wch, dummy, str[i].attrs, 0, 0) == ERR)
+ {
+ rval=ERR;
+ if(setcchar(&wch, L"?", get_style("Error").get_attrs(), 0, 0) == ERR)
+ continue;
+ }
+
+ if(wadd_wch(win, &wch) == ERR)
+ rval=ERR;
+ }
+
+ return rval;
+}
+
+int cwindow::mvaddstr(int y, int x, const wchstring &str)
+{
+ return mvaddnstr(y, x, str, str.size());
+}
+
+int cwindow::mvaddnstr(int y, int x, const wchstring &str, size_t n)
+{
+ if(move(y, x) == ERR)
+ return ERR;
+ else
+ return addnstr(str, n);
+}
Modified: branches/aptitude-0.3/aptitude/src/vscreen/curses++.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/curses++.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/curses++.h Sat Jun 25 16:13:34 2005
@@ -218,6 +218,9 @@
/** Change the attributes of this string by using the given style. */
void apply_style(const style &st);
+
+ /** Return the number of columns occupied by this string. */
+ int width() const;
};
inline chtype _getbkgd(WINDOW *win)
@@ -442,6 +445,13 @@
int mvaddstr(int y, int x, const char *str) {return mvwaddstr(win, y, x, str);}
int mvaddnstr(int y, int x, const char *str, int n) {return mvwaddnstr(win, y, x, str, n);}
+ // The following are implemented hackily due to the weirdness of
+ // curses. NB: they don't work with characters of negative width.
+ int addstr(const wchstring &str);
+ int addnstr(const wchstring &str, size_t n);
+ int mvaddstr(int y, int x, const wchstring &str);
+ int mvaddnstr(int y, int x, const wchstring &str, size_t n);
+
int addstr(const chstring &str) {return waddchstr(win, str.c_str());}
int addnstr(const chstring &str, int n) {return waddchnstr(win, str.c_str(), n);}
int mvaddstr(int y, int x, const chstring &str) {return mvwaddchstr(win, y, x, str.c_str());}