1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
26 #include <readline/history.h>
27 #include <readline/readline.h>
29 #include <sys/select.h>
32 #include "utility/string.h"
33 #include "utility/wide_string.h"
38 struct ScopedWindowTimeout
40 ScopedWindowTimeout(WINDOW
*w
, int init_timeout
, int term_timeout
)
41 : m_w(w
), m_term_timeout(term_timeout
) {
42 wtimeout(w
, init_timeout
);
44 ~ScopedWindowTimeout() {
45 wtimeout(m_w
, m_term_timeout
);
72 if (w
->runPromptHook(rl_line_buffer
, &done
))
79 w
->goToXY(x
, start_y
);
82 result
= w
->readKey();
83 if (!w
->FDCallbacksListEmpty())
85 w
->goToXY(x
, start_y
);
89 while (result
== ERR
);
95 auto print_char
= [](wchar_t wc
) {
101 auto print_string
= [](wchar_t *ws
, size_t len
) {
103 for (size_t i
= 0; i
< len
; ++i
)
108 auto narrow_to_wide
= [](wchar_t *dest
, const char *src
, size_t n
) {
110 // convert the string and substitute invalid multibyte chars with dots.
111 for (size_t i
= 0; i
< n
;)
113 int ret
= mbtowc(&dest
[result
], &src
[i
], n
-i
);
126 throw std::runtime_error("mbtowc: unexpected return value");
131 // copy the part of the string that is before the cursor to pre_pos
132 char pt
= rl_line_buffer
[rl_point
];
133 rl_line_buffer
[rl_point
] = 0;
134 wchar_t pre_pos
[rl_point
+1];
135 pre_pos
[narrow_to_wide(pre_pos
, rl_line_buffer
, rl_point
)] = 0;
136 rl_line_buffer
[rl_point
] = pt
;
138 int pos
= wcswidth(pre_pos
, rl_point
);
142 // clear the area for the string
143 mvwhline(w
->raw(), start_y
, start_x
, ' ', width
+1);
145 w
->goToXY(start_x
, start_y
);
146 if (size_t(pos
) <= width
)
148 // if the current position in the string is not bigger than allowed
149 // width, print the part of the string before cursor position...
151 print_string(pre_pos
, pos
);
153 // ...and then print the rest char-by-char until there is no more area
154 wchar_t post_pos
[rl_end
-rl_point
+1];
155 post_pos
[narrow_to_wide(post_pos
, rl_line_buffer
+rl_point
, rl_end
-rl_point
)] = 0;
158 for (wchar_t *c
= post_pos
; *c
!= 0; ++c
)
177 // if the current position in the string is bigger than allowed
178 // width, we always keep the cursor at the end of the line (it
179 // would be nice to have more flexible scrolling, but for now
180 // let's stick to that) by cutting the beginning of the part
181 // of the string before the cursor until it fits the area.
183 wchar_t *mod_pre_pos
= pre_pos
;
184 while (*mod_pre_pos
!= 0)
187 int n
= wcwidth(*mod_pre_pos
);
192 if (size_t(pos
) <= width
)
195 print_string(mod_pre_pos
, pos
);
197 w
->goToXY(start_x
+pos
, start_y
);
202 rl_insert_text(base
);
211 const short Color::transparent
= -1;
212 const short Color::previous
= -2;
214 Color
Color::Default(0, 0, true, false);
215 Color
Color::Black(COLOR_BLACK
, Color::transparent
);
216 Color
Color::Red(COLOR_RED
, Color::transparent
);
217 Color
Color::Green(COLOR_GREEN
, Color::transparent
);
218 Color
Color::Yellow(COLOR_YELLOW
, Color::transparent
);
219 Color
Color::Blue(COLOR_BLUE
, Color::transparent
);
220 Color
Color::Magenta(COLOR_MAGENTA
, Color::transparent
);
221 Color
Color::Cyan(COLOR_CYAN
, Color::transparent
);
222 Color
Color::White(COLOR_WHITE
, Color::transparent
);
223 Color
Color::End(0, 0, false, true);
225 int Color::pairNumber() const
230 else if (previousBackground())
231 throw std::logic_error("color depends on the previous background value");
233 throw std::logic_error("'end' doesn't have a corresponding pair number");
236 // colors start with 0, but pairs start with 1. additionally
237 // first pairs are for transparent background, which has a
238 // value of -1, so we need to add 1 to both foreground and
240 result
= background() + 1;
242 result
+= foreground() + 1;
247 std::istream
&operator>>(std::istream
&is
, Color
&c
)
249 auto get_single_color
= [](const std::string
&s
, bool background
) {
252 result
= COLOR_BLACK
;
255 else if (s
== "green")
256 result
= COLOR_GREEN
;
257 else if (s
== "yellow")
258 result
= COLOR_YELLOW
;
259 else if (s
== "blue")
261 else if (s
== "magenta")
262 result
= COLOR_MAGENTA
;
263 else if (s
== "cyan")
265 else if (s
== "white")
266 result
= COLOR_WHITE
;
267 else if (background
&& s
== "previous")
268 result
= NC::Color::previous
;
269 else if (std::all_of(s
.begin(), s
.end(), isdigit
))
271 result
= atoi(s
.c_str());
272 if (result
< 1 || result
> 256)
283 else if (sc
== "end")
287 short value
= get_single_color(sc
, false);
289 c
= Color(value
, NC::Color::transparent
);
292 size_t underscore
= sc
.find('_');
293 if (underscore
!= std::string::npos
)
295 short fg
= get_single_color(sc
.substr(0, underscore
), false);
296 short bg
= get_single_color(sc
.substr(underscore
+1), true);
297 if (fg
!= -1 && bg
!= -1)
300 is
.setstate(std::ios::failbit
);
303 is
.setstate(std::ios::failbit
);
313 bool mouseEnabled
= false;
321 # if NCURSES_SEQUENCE_ESCAPING
322 mousemask(ALL_MOUSE_EVENTS
, nullptr);
324 // save old highlight mouse tracking
326 // enable mouse tracking
328 // try to enable extended (urxvt) mouse tracking
330 # endif // NCURSES_SEQUENCE_ESCAPING
338 # if NCURSES_SEQUENCE_ESCAPING
339 mousemask(0, nullptr);
341 // disable extended (urxvt) mouse tracking
343 // disable mouse tracking
345 // restore old highlight mouse tracking
347 # endif // NCURSES_SEQUENCE_ESCAPING
348 mouseEnabled
= false;
353 void initScreen(bool enable_colors
, bool enable_mouse
)
356 if (has_colors() && enable_colors
)
359 use_default_colors();
361 for (int bg
= -1; bg
< COLORS
; ++bg
)
363 for (int fg
= 0; npair
< COLOR_PAIRS
&& fg
< COLORS
; ++fg
, ++npair
)
364 init_pair(npair
, fg
, bg
);
373 # if NCURSES_SEQUENCE_ESCAPING
375 # endif // NCURSES_SEQUENCE_ESCAPING
379 // initialize readline (needed, otherwise we get segmentation
380 // fault on SIGWINCH). also, initialize first as doing this
381 // later erases keys bound with rl_bind_key for some users.
383 // disable autocompletion
384 rl_attempted_completion_function
= [](const char *, int, int) -> char ** {
385 rl_attempted_completion_over
= 1;
388 auto abort_prompt
= [](int, int) -> int {
393 // if ctrl-c or ctrl-g is pressed, abort the prompt
394 rl_bind_key(KEY_CTRL_C
, abort_prompt
);
395 rl_bind_key(KEY_CTRL_G
, abort_prompt
);
396 // do not change the state of the terminal
397 rl_prep_term_function
= nullptr;
398 rl_deprep_term_function
= nullptr;
399 // do not catch signals
400 rl_catch_signals
= 0;
401 // overwrite readline callbacks
402 rl_getc_function
= rl::read_key
;
403 rl_redisplay_function
= rl::display_string
;
404 rl_startup_hook
= rl::add_base
;
414 Window::Window(size_t startx
,
426 m_window_timeout(-1),
429 m_border(std::move(border
)),
431 m_title(std::move(title
)),
432 m_escape_terminal_sequences(true),
434 m_underline_counter(0),
435 m_reverse_counter(0),
436 m_alt_charset_counter(0)
438 if (m_start_x
> size_t(COLS
)
439 || m_start_y
> size_t(LINES
)
440 || m_width
+m_start_x
> size_t(COLS
)
441 || m_height
+m_start_y
> size_t(LINES
))
442 throw std::logic_error("constructed window doesn't fit into the terminal");
451 if (!m_title
.empty())
457 m_window
= newpad(m_height
, m_width
);
460 # if NCURSES_SEQUENCE_ESCAPING
462 # endif // NCURSES_SEQUENCE_ESCAPING
465 Window::Window(const Window
&rhs
)
466 : m_window(dupwin(rhs
.m_window
))
467 , m_start_x(rhs
.m_start_x
)
468 , m_start_y(rhs
.m_start_y
)
469 , m_width(rhs
.m_width
)
470 , m_height(rhs
.m_height
)
471 , m_window_timeout(rhs
.m_window_timeout
)
472 , m_color(rhs
.m_color
)
473 , m_base_color(rhs
.m_base_color
)
474 , m_border(rhs
.m_border
)
475 , m_prompt_hook(rhs
.m_prompt_hook
)
476 , m_title(rhs
.m_title
)
477 , m_color_stack(rhs
.m_color_stack
)
478 , m_input_queue(rhs
.m_input_queue
)
480 , m_escape_terminal_sequences(rhs
.m_escape_terminal_sequences
)
481 , m_bold_counter(rhs
.m_bold_counter
)
482 , m_underline_counter(rhs
.m_underline_counter
)
483 , m_reverse_counter(rhs
.m_reverse_counter
)
484 , m_alt_charset_counter(rhs
.m_alt_charset_counter
)
488 Window::Window(Window
&&rhs
)
489 : m_window(rhs
.m_window
)
490 , m_start_x(rhs
.m_start_x
)
491 , m_start_y(rhs
.m_start_y
)
492 , m_width(rhs
.m_width
)
493 , m_height(rhs
.m_height
)
494 , m_window_timeout(rhs
.m_window_timeout
)
495 , m_color(rhs
.m_color
)
496 , m_base_color(rhs
.m_base_color
)
497 , m_border(rhs
.m_border
)
498 , m_prompt_hook(rhs
.m_prompt_hook
)
499 , m_title(std::move(rhs
.m_title
))
500 , m_color_stack(std::move(rhs
.m_color_stack
))
501 , m_input_queue(std::move(rhs
.m_input_queue
))
502 , m_fds(std::move(rhs
.m_fds
))
503 , m_escape_terminal_sequences(rhs
.m_escape_terminal_sequences
)
504 , m_bold_counter(rhs
.m_bold_counter
)
505 , m_underline_counter(rhs
.m_underline_counter
)
506 , m_reverse_counter(rhs
.m_reverse_counter
)
507 , m_alt_charset_counter(rhs
.m_alt_charset_counter
)
509 rhs
.m_window
= nullptr;
512 Window
&Window::operator=(Window rhs
)
514 std::swap(m_window
, rhs
.m_window
);
515 std::swap(m_start_x
, rhs
.m_start_x
);
516 std::swap(m_start_y
, rhs
.m_start_y
);
517 std::swap(m_width
, rhs
.m_width
);
518 std::swap(m_height
, rhs
.m_height
);
519 std::swap(m_window_timeout
, rhs
.m_window_timeout
);
520 std::swap(m_color
, rhs
.m_color
);
521 std::swap(m_base_color
, rhs
.m_base_color
);
522 std::swap(m_border
, rhs
.m_border
);
523 std::swap(m_prompt_hook
, rhs
.m_prompt_hook
);
524 std::swap(m_title
, rhs
.m_title
);
525 std::swap(m_color_stack
, rhs
.m_color_stack
);
526 std::swap(m_input_queue
, rhs
.m_input_queue
);
527 std::swap(m_fds
, rhs
.m_fds
);
528 std::swap(m_escape_terminal_sequences
, rhs
.m_escape_terminal_sequences
);
529 std::swap(m_bold_counter
, rhs
.m_bold_counter
);
530 std::swap(m_underline_counter
, rhs
.m_underline_counter
);
531 std::swap(m_reverse_counter
, rhs
.m_reverse_counter
);
532 std::swap(m_alt_charset_counter
, rhs
.m_alt_charset_counter
);
541 void Window::setColor(Color c
)
545 if (c
!= Color::Default
)
547 if (c
.previousBackground())
548 c
= Color(c
.foreground(), m_color
.background());
549 wcolor_set(m_window
, c
.pairNumber(), nullptr);
552 wcolor_set(m_window
, m_base_color
.pairNumber(), nullptr);
553 m_color
= std::move(c
);
556 void Window::setBaseColor(Color c
)
558 m_base_color
= std::move(c
);
561 void Window::setBorder(Border border
)
563 if (!border
&& m_border
)
569 recreate(m_width
, m_height
);
571 else if (border
&& !m_border
)
577 recreate(m_width
, m_height
);
582 void Window::setTitle(const std::string
&new_title
)
584 if (!new_title
.empty() && m_title
.empty())
588 recreate(m_width
, m_height
);
590 else if (new_title
.empty() && !m_title
.empty())
594 recreate(m_width
, m_height
);
599 void Window::recreate(size_t width
, size_t height
)
602 m_window
= newpad(height
, width
);
603 setTimeout(m_window_timeout
);
605 # if NCURSES_SEQUENCE_ESCAPING
607 # endif // NCURSES_SEQUENCE_ESCAPING
610 void Window::moveTo(size_t new_x
, size_t new_y
)
619 if (!m_title
.empty())
623 void Window::adjustDimensions(size_t width
, size_t height
)
630 if (!m_title
.empty())
636 void Window::resize(size_t new_width
, size_t new_height
)
638 adjustDimensions(new_width
, new_height
);
639 recreate(m_width
, m_height
);
642 void Window::refreshBorder() const
646 size_t start_x
= getStartX(), start_y
= getStarty();
647 size_t width
= getWidth(), height
= getHeight();
648 color_set(m_border
->pairNumber(), nullptr);
649 attron(A_ALTCHARSET
);
651 mvaddch(start_y
, start_x
, 'l');
652 mvaddch(start_y
, start_x
+width
-1, 'k');
653 mvaddch(start_y
+height
-1, start_x
, 'm');
654 mvaddch(start_y
+height
-1, start_x
+width
-1, 'j');
656 mvhline(start_y
, start_x
+1, 'q', width
-2);
657 mvhline(start_y
+height
-1, start_x
+1, 'q', width
-2);
658 mvvline(start_y
+1, start_x
, 'x', height
-2);
659 mvvline(start_y
+1, start_x
+width
-1, 'x', height
-2);
660 if (!m_title
.empty())
662 mvaddch(start_y
+2, start_x
, 't');
663 mvaddch(start_y
+2, start_x
+width
-1, 'u');
665 attroff(A_ALTCHARSET
);
668 color_set(m_base_color
.pairNumber(), nullptr);
669 if (!m_title
.empty())
672 mvhline(m_start_y
-2, m_start_x
, ' ', m_width
);
674 mvaddstr(m_start_y
-2, m_start_x
, m_title
.c_str());
677 mvhline(m_start_y
-1, m_start_x
, 0, m_width
);
683 void Window::display()
689 void Window::refresh()
691 prefresh(m_window
, 0, 0, m_start_y
, m_start_x
, m_start_y
+m_height
-1, m_start_x
+m_width
-1);
699 void Window::bold(bool bold_state
) const
701 (bold_state
? wattron
: wattroff
)(m_window
, A_BOLD
);
704 void Window::underline(bool underline_state
) const
706 (underline_state
? wattron
: wattroff
)(m_window
, A_UNDERLINE
);
709 void Window::reverse(bool reverse_state
) const
711 (reverse_state
? wattron
: wattroff
)(m_window
, A_REVERSE
);
714 void Window::altCharset(bool altcharset_state
) const
716 (altcharset_state
? wattron
: wattroff
)(m_window
, A_ALTCHARSET
);
719 void Window::setTimeout(int timeout
)
721 if (timeout
!= m_window_timeout
)
723 m_window_timeout
= timeout
;
724 wtimeout(m_window
, timeout
);
728 void Window::addFDCallback(int fd
, void (*callback
)())
730 m_fds
.push_back(std::make_pair(fd
, callback
));
733 void Window::clearFDCallbacksList()
738 bool Window::FDCallbacksListEmpty() const
740 return m_fds
.empty();
743 int Window::getInputChar()
745 # if NCURSES_SEQUENCE_ESCAPING
746 return wgetch(m_window
);
748 int key
= wgetch(m_window
);
749 if (!m_escape_terminal_sequences
|| key
!= KEY_ESCAPE
)
751 auto define_mouse_event
= [this](int type
) {
755 m_mouse_event
.bstate
= BUTTON1_PRESSED
;
758 m_mouse_event
.bstate
= BUTTON2_PRESSED
;
761 m_mouse_event
.bstate
= BUTTON3_PRESSED
;
764 m_mouse_event
.bstate
= BUTTON4_PRESSED
;
767 m_mouse_event
.bstate
= BUTTON5_PRESSED
;
773 m_mouse_event
.bstate
|= BUTTON_SHIFT
;
775 m_mouse_event
.bstate
|= BUTTON_ALT
;
777 m_mouse_event
.bstate
|= BUTTON_CTRL
;
778 if (m_mouse_event
.x
< 0 || m_mouse_event
.x
>= COLS
)
780 if (m_mouse_event
.y
< 0 || m_mouse_event
.y
>= LINES
)
784 auto parse_number
= [this](int &result
) {
788 x
= wgetch(m_window
);
791 result
= result
*10 + x
- '0';
794 ScopedWindowTimeout
swt(m_window
, 0, m_window_timeout
);
795 key
= wgetch(m_window
);
799 return KEY_SHIFT_TAB
;
800 case 'O': // F1 to F4 in xterm
801 key
= wgetch(m_window
);
822 key
= wgetch(m_window
);
839 key
= wgetch(m_window
);
840 int raw_x
= wgetch(m_window
);
841 int raw_y
= wgetch(m_window
);
842 // support coordinates up to 255
843 m_mouse_event
.x
= (raw_x
- 33) & 0xff;
844 m_mouse_event
.y
= (raw_y
- 33) & 0xff;
845 return define_mouse_event(key
);
848 return KEY_SHIFT_TAB
;
849 case '[': // F1 to F5 in tty
850 key
= wgetch(m_window
);
873 case '1': case '2': case '3':
874 case '4': case '5': case '6':
875 case '7': case '8': case '9':
878 int delim
= parse_number(key
);
896 case 17: // not a typo
908 case 23: // not a typo
927 case ';': // urxvt mouse
929 delim
= parse_number(m_mouse_event
.x
);
933 delim
= parse_number(m_mouse_event
.y
);
938 return define_mouse_event(key
);
950 m_input_queue
.push(key
);
953 # endif // NCURSES_SEQUENCE_ESCAPING
956 int Window::readKey()
959 // if there are characters in input queue,
960 // get them and return immediately.
961 if (!m_input_queue
.empty())
963 result
= m_input_queue
.front();
970 FD_SET(STDIN_FILENO
, &fdset
);
971 timeval timeout
= { m_window_timeout
/1000, (m_window_timeout
%1000)*1000 };
973 int fd_max
= STDIN_FILENO
;
974 for (FDCallbacks::const_iterator it
= m_fds
.begin(); it
!= m_fds
.end(); ++it
)
976 if (it
->first
> fd_max
)
978 FD_SET(it
->first
, &fdset
);
981 if (select(fd_max
+1, &fdset
, 0, 0, m_window_timeout
< 0 ? 0 : &timeout
) > 0)
983 result
= FD_ISSET(STDIN_FILENO
, &fdset
) ? getInputChar() : ERR
;
985 for (FDCallbacks::const_iterator it
= m_fds
.begin(); it
!= m_fds
.end(); ++it
)
986 if (FD_ISSET(it
->first
, &fdset
))
994 void Window::pushChar(int ch
)
996 m_input_queue
.push(ch
);
999 std::string
Window::prompt(const std::string
&base
, size_t width
, bool encrypted
)
1003 rl::aborted
= false;
1005 getyx(m_window
, rl::start_y
, rl::start_x
);
1006 rl::width
= std::min(m_width
-rl::start_x
-1, width
-1);
1007 rl::encrypted
= encrypted
;
1008 rl::base
= base
.c_str();
1011 # if NCURSES_SEQUENCE_ESCAPING
1012 keypad(m_window
, 0);
1013 # endif // NCURSES_SEQUENCE_ESCAPING
1015 m_escape_terminal_sequences
= false;
1016 char *input
= readline(nullptr);
1017 m_escape_terminal_sequences
= true;
1019 # if NCURSES_SEQUENCE_ESCAPING
1020 keypad(m_window
, 1);
1021 # endif // NCURSES_SEQUENCE_ESCAPING
1023 if (input
!= nullptr)
1025 if (!encrypted
&& input
[0] != 0)
1032 throw PromptAborted(std::move(result
));
1037 void Window::goToXY(int x
, int y
)
1039 wmove(m_window
, y
, x
);
1044 return getcurx(m_window
);
1049 return getcury(m_window
);
1052 bool Window::hasCoords(int &x
, int &y
)
1054 return wmouse_trafo(m_window
, &y
, &x
, 0);
1057 bool Window::runPromptHook(const char *arg
, bool *done
) const
1061 bool continue_
= m_prompt_hook(arg
);
1062 if (done
!= nullptr)
1070 size_t Window::getWidth() const
1078 size_t Window::getHeight() const
1080 size_t height
= m_height
;
1083 if (!m_title
.empty())
1088 size_t Window::getStartX() const
1096 size_t Window::getStarty() const
1098 size_t starty
= m_start_y
;
1101 if (!m_title
.empty())
1106 const std::string
&Window::getTitle() const
1111 const Color
&Window::getColor() const
1116 const Border
&Window::getBorder() const
1121 int Window::getTimeout() const
1123 return m_window_timeout
;
1126 const MEVENT
&Window::getMouseEvent()
1128 # if NCURSES_SEQUENCE_ESCAPING
1129 getmouse(&m_mouse_event
);
1130 # endif // NCURSES_SEQUENCE_ESCAPING
1131 return m_mouse_event
;
1134 void Window::scroll(Scroll where
)
1137 scrollok(m_window
, 1);
1144 wscrl(m_window
, -1);
1146 case Scroll::PageUp
:
1147 wscrl(m_window
, m_width
);
1149 case Scroll::PageDown
:
1150 wscrl(m_window
, -m_width
);
1156 scrollok(m_window
, 0);
1160 Window
&Window::operator<<(const Color
&c
)
1164 while (!m_color_stack
.empty())
1165 m_color_stack
.pop();
1166 setColor(m_base_color
);
1170 if (!m_color_stack
.empty())
1171 m_color_stack
.pop();
1172 if (!m_color_stack
.empty())
1173 setColor(m_color_stack
.top());
1175 setColor(m_base_color
);
1180 m_color_stack
.push(c
);
1185 Window
&Window::operator<<(Format format
)
1190 bold((m_bold_counter
= 0));
1191 reverse((m_reverse_counter
= 0));
1192 altCharset((m_alt_charset_counter
= 0));
1195 bold(++m_bold_counter
);
1197 case Format::NoBold
:
1198 if (--m_bold_counter
<= 0)
1199 bold((m_bold_counter
= 0));
1201 case Format::Underline
:
1202 underline(++m_underline_counter
);
1204 case Format::NoUnderline
:
1205 if (--m_underline_counter
<= 0)
1206 underline((m_underline_counter
= 0));
1208 case Format::Reverse
:
1209 reverse(++m_reverse_counter
);
1211 case Format::NoReverse
:
1212 if (--m_reverse_counter
<= 0)
1213 reverse((m_reverse_counter
= 0));
1215 case Format::AltCharset
:
1216 altCharset(++m_alt_charset_counter
);
1218 case Format::NoAltCharset
:
1219 if (--m_alt_charset_counter
<= 0)
1220 altCharset((m_alt_charset_counter
= 0));
1226 Window
&Window::operator<<(TermManip tm
)
1230 case TermManip::ClearToEOL
:
1232 auto x
= getX(), y
= getY();
1233 mvwhline(m_window
, y
, x
, ' ', m_width
-x
);
1241 Window
&Window::operator<<(const XY
&coords
)
1243 goToXY(coords
.x
, coords
.y
);
1247 Window
&Window::operator<<(const char *s
)
1249 waddstr(m_window
, s
);
1253 Window
&Window::operator<<(char c
)
1255 // waddchr doesn't display non-ascii multibyte characters properly
1256 waddnstr(m_window
, &c
, 1);
1260 Window
&Window::operator<<(const wchar_t *ws
)
1262 # ifdef NCMPCPP_UNICODE
1263 waddwstr(m_window
, ws
);
1265 wprintw(m_window
, "%ls", ws
);
1266 # endif // NCMPCPP_UNICODE
1270 Window
&Window::operator<<(wchar_t wc
)
1272 # ifdef NCMPCPP_UNICODE
1273 waddnwstr(m_window
, &wc
, 1);
1275 wprintw(m_window
, "%lc", wc
);
1276 # endif // NCMPCPP_UNICODE
1280 Window
&Window::operator<<(int i
)
1282 wprintw(m_window
, "%d", i
);
1286 Window
&Window::operator<<(double d
)
1288 wprintw(m_window
, "%f", d
);
1292 Window
&Window::operator<<(const std::string
&s
)
1294 waddnstr(m_window
, s
.c_str(), s
.length());
1298 Window
&Window::operator<<(const std::wstring
&ws
)
1300 # ifdef NCMPCPP_UNICODE
1301 waddnwstr(m_window
, ws
.c_str(), ws
.length());
1303 wprintw(m_window
, "%lc", ws
.c_str());
1304 # endif // NCMPCPP_UNICODE
1308 Window
&Window::operator<<(size_t s
)
1310 wprintw(m_window
, "%zu", s
);