Move TUI command window code
[external/binutils.git] / gdb / tui / tui-file.c
1 /* UI_FILE - a generic STDIO like output stream.
2    Copyright (C) 1999-2019 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #include "defs.h"
20 #include "tui/tui-file.h"
21 #include "tui/tui-io.h"
22 #include "tui/tui-command.h"
23 #include "tui.h"
24
25 tui_file::tui_file (FILE *stream)
26   : stdio_file (stream)
27 {}
28
29 /* All TUI I/O sent to the *_filtered and *_unfiltered functions
30    eventually ends up here.  The fputs_unfiltered_hook is primarily
31    used by GUIs to collect all output and send it to the GUI, instead
32    of the controlling terminal.  Only output to gdb_stdout and
33    gdb_stderr are sent to the hook.  Everything else is sent on to
34    fputs to allow file I/O to be handled appropriately.  */
35
36 void
37 tui_file::puts (const char *linebuffer)
38 {
39   tui_puts (linebuffer);
40   /* gdb_stdout is buffered, and the caller must gdb_flush it at
41      appropriate times.  Other streams are not so buffered.  */
42   if (this != gdb_stdout)
43     tui_refresh_cmd_win ();
44 }
45
46 void
47 tui_file::write (const char *buf, long length_buf)
48 {
49   tui_write (buf, length_buf);
50   /* gdb_stdout is buffered, and the caller must gdb_flush it at
51      appropriate times.  Other streams are not so buffered.  */
52   if (this != gdb_stdout)
53     tui_refresh_cmd_win ();
54 }
55
56 void
57 tui_file::flush ()
58 {
59   /* gdb_stdout is buffered.  Other files are always flushed on
60      every write.  */
61   if (this == gdb_stdout)
62     tui_refresh_cmd_win ();
63   stdio_file::flush ();
64 }