diff options
author | Marcus Brinkmann <marcus@gnu.org> | 2002-09-13 23:40:10 +0000 |
---|---|---|
committer | Marcus Brinkmann <marcus@gnu.org> | 2002-09-13 23:40:10 +0000 |
commit | cc60ad8bb9596cafe94f48de9ea030ce01e22404 (patch) | |
tree | ba7b74a5ab8d70d7505c514c6d63929a9bcaded3 /libcons | |
parent | fad9d77677aca4ce2fd11705f87adca9b0524ecf (diff) |
2002-09-14 Marcus Brinkmann <marcus@gnu.org>
* Makefile (SRCS): Add vcons-input.c.
* vcons-input.c: New file.
* vcons-scrollback.c (_cons_vcons_scrollback): New function.
(cons_vcons_scrollback): Reimplement in terms of
_cons_vcons_scrollback.
* cons.h (cons_scroll_t): New type.
(cons_vcons_scrollback): Update prototype.
* priv.h (_cons_jump_down_at_input): New extern.
(_cons_jump_down_at_output): Likewise.
(_cons_vcons_scrollback): New prototype.
* opts-std-startup.c (OPT_JUMP_DOWN_AT_INPUT): New macro.
(OPT_JUMP_DOWN_AT_OUTPUT): Likewise.
(_cons_jump_down_at_input): New variable.
(_cons_jump_down_at_output): Likewise.
(startup_options): Add new options --jump-down-at-input and
--jump-down-at-output.
(parse_startup_opt): Handle these new options.
* file-changed.c (cons_S_file_changed): Support the jump down at
output option.
Diffstat (limited to 'libcons')
-rw-r--r-- | libcons/ChangeLog | 24 | ||||
-rw-r--r-- | libcons/Makefile | 3 | ||||
-rw-r--r-- | libcons/cons.h | 25 | ||||
-rw-r--r-- | libcons/file-changed.c | 28 | ||||
-rw-r--r-- | libcons/opts-std-startup.c | 22 | ||||
-rw-r--r-- | libcons/priv.h | 11 | ||||
-rw-r--r-- | libcons/vcons-input.c | 54 | ||||
-rw-r--r-- | libcons/vcons-scrollback.c | 65 |
8 files changed, 204 insertions, 28 deletions
diff --git a/libcons/ChangeLog b/libcons/ChangeLog index 6b21a264..a6e5c3c3 100644 --- a/libcons/ChangeLog +++ b/libcons/ChangeLog @@ -1,3 +1,27 @@ +2002-09-14 Marcus Brinkmann <marcus@gnu.org> + + * Makefile (SRCS): Add vcons-input.c. + * vcons-input.c: New file. + + * vcons-scrollback.c (_cons_vcons_scrollback): New function. + (cons_vcons_scrollback): Reimplement in terms of + _cons_vcons_scrollback. + * cons.h (cons_scroll_t): New type. + (cons_vcons_scrollback): Update prototype. + + * priv.h (_cons_jump_down_at_input): New extern. + (_cons_jump_down_at_output): Likewise. + (_cons_vcons_scrollback): New prototype. + * opts-std-startup.c (OPT_JUMP_DOWN_AT_INPUT): New macro. + (OPT_JUMP_DOWN_AT_OUTPUT): Likewise. + (_cons_jump_down_at_input): New variable. + (_cons_jump_down_at_output): Likewise. + (startup_options): Add new options --jump-down-at-input and + --jump-down-at-output. + (parse_startup_opt): Handle these new options. + * file-changed.c (cons_S_file_changed): Support the jump down at + output option. + 2002-09-10 Marcus Brinkmann <marcus@gnu.org> * file-changed.c (cons_S_file_changed): Fix typo in last change. diff --git a/libcons/Makefile b/libcons/Makefile index 2a677e7d..576f8b66 100644 --- a/libcons/Makefile +++ b/libcons/Makefile @@ -22,7 +22,8 @@ libname = libcons SRCS= demuxer.c init-init.c init-loop.c opts-version.c extra-version.c \ dir-changed.c file-changed.c opts-std-startup.c cons-lookup.c \ cons-switch.c vcons-remove.c vcons-add.c vcons-open.c \ - vcons-close.c vcons-destroy.c vcons-refresh.c vcons-scrollback.c + vcons-close.c vcons-destroy.c vcons-refresh.c vcons-scrollback.c \ + vcons-input.c LCLHDRS = priv.h mutations.h installhdrs = cons.h diff --git a/libcons/cons.h b/libcons/cons.h index 783aeb6a..67f4e45b 100644 --- a/libcons/cons.h +++ b/libcons/cons.h @@ -189,7 +189,7 @@ void cons_vcons_scroll (vcons_t vcons, int delta); void cons_vcons_update (vcons_t vcons); /* The user must define this function. Make the virtual console - VCONS, which is locked, beep audible. */ + VCONS, which is locked, beep audibly. */ void cons_vcons_beep (vcons_t vcons); /* The user must define this function. Make the virtual console @@ -218,8 +218,27 @@ void cons_vcons_remove (cons_t cons, vcons_list_t vcons_entry); be locked. */ error_t cons_switch (vcons_t vcons, int id, int delta, vcons_t *r_vcons); -/* Scroll back into the history of VCONS by DELTA lines. */ -int cons_vcons_scrollback (vcons_t vcons, int delta); +/* Enter SIZE bytes from the buffer BUF into the virtual console + VCONS. */ +error_t cons_vcons_input (vcons_t vcons, char *buf, size_t size); + +typedef enum + { + CONS_SCROLL_DELTA_LINES, CONS_SCROLL_DELTA_SCREENS, + CONS_SCROLL_ABSOLUTE_LINE, CONS_SCROLL_ABSOLUTE_PERCENTAGE + } cons_scroll_t; + +/* Scroll back into the history of VCONS. If TYPE is + CONS_SCROLL_DELTA_LINES, scroll up or down by VALUE lines. If TYPE + is CONS_SCROLL_DELTA_SCREENS, scroll up or down by VALUE multiples + of a screen height. If TYPE is CONS_SCROLL_ABSOLUTE_LINE, scroll to + line VALUE (where 0 is the lowest line). If TYPE is + CONS_SCROLL_ABSOLUTE_PERCENTAGE, scroll to the position determined + by VALUE, where 0 is the bottom and 1 is the top. + + The function returns the number of lines actually scrolled up or + down. */ +int cons_vcons_scrollback (vcons_t vcons, cons_scroll_t type, float value); extern const struct argp cons_startup_argp; diff --git a/libcons/file-changed.c b/libcons/file-changed.c index 2c91fe51..21449271 100644 --- a/libcons/file-changed.c +++ b/libcons/file-changed.c @@ -124,19 +124,28 @@ cons_S_file_changed (cons_notify_t notify, natural_t tickno, scrolling = UINT32_MAX - vcons->state.screen.cur_line + 1 + new_cur_line; - /* If we are scrollbacking, defer scrolling + /* If we are scrolling back, defer scrolling until absolutely necessary. */ if (vcons->scrolling) { - if (vcons->scrolling + scrolling <= vcons->state.screen.scr_lines) - { - vcons->scrolling += scrolling; - scrolling = 0; - } + if (_cons_jump_down_at_output) + _cons_vcons_scrollback + (vcons, CONS_SCROLL_ABSOLUTE_LINE, 0); else { - scrolling -= vcons->state.screen.scr_lines - vcons->scrolling; - vcons->scrolling = vcons->state.screen.scr_lines; + if (vcons->scrolling + scrolling + <= vcons->state.screen.scr_lines) + { + vcons->scrolling += scrolling; + scrolling = 0; + } + else + { + scrolling -= vcons->state.screen.scr_lines + - vcons->scrolling; + vcons->scrolling + = vcons->state.screen.scr_lines; + } } } @@ -225,6 +234,9 @@ cons_S_file_changed (cons_notify_t notify, natural_t tickno, off_t start = change.matrix.start; off_t end = change.matrix.end; + if (vcons->scrolling && _cons_jump_down_at_output) + _cons_vcons_scrollback (vcons, CONS_SCROLL_ABSOLUTE_LINE, 0); + if (vcons->state.screen.cur_line >= vcons->scrolling) rotate = vcons->state.screen.cur_line - vcons->scrolling; else diff --git a/libcons/opts-std-startup.c b/libcons/opts-std-startup.c index c4a7d7bd..f64f60fc 100644 --- a/libcons/opts-std-startup.c +++ b/libcons/opts-std-startup.c @@ -25,7 +25,9 @@ /* Option keys for long-only options in diskfs_common_options. */ -#define OPT_SLACK 600 /* --slack */ +#define OPT_SLACK 600 /* --slack */ +#define OPT_JUMP_DOWN_AT_INPUT 601 /* --jump-down-at-input */ +#define OPT_JUMP_DOWN_AT_OUTPUT 602 /* --jump-down-at-output */ /* Common value for diskfs_common_options and diskfs_default_sync_interval. */ #define DEFAULT_SLACK 100 @@ -37,6 +39,12 @@ server. */ int _cons_slack = DEFAULT_SLACK; +/* If we jump down at input. */ +int _cons_jump_down_at_input; + +/* If we jump down at output. */ +int _cons_jump_down_at_output; + /* The filename of the console server. */ char *_cons_file; @@ -45,6 +53,10 @@ startup_options[] = { { "slack", OPT_SLACK, "RECORDS", 0, "Max number of records the client is" " allowed to lag behind the server (default " DEFAULT_SLACK_STRING ")" }, + { "jump-down-at-input", OPT_JUMP_DOWN_AT_INPUT, NULL, 0, + "End scrollback when something is entered" }, + { "jump-down-at-output", OPT_JUMP_DOWN_AT_OUTPUT, NULL, 0, + "End scrollback when something is printed" }, { 0, 0 } }; @@ -61,6 +73,14 @@ parse_startup_opt (int opt, char *arg, struct argp_state *state) _cons_slack = atoi (arg); break; + case OPT_JUMP_DOWN_AT_INPUT: + _cons_jump_down_at_input = 1; + break; + + case OPT_JUMP_DOWN_AT_OUTPUT: + _cons_jump_down_at_output = 1; + break; + case ARGP_KEY_ARG: if (state->arg_num > 0) /* Too many arguments. */ diff --git a/libcons/priv.h b/libcons/priv.h index c99a1600..9f3fd7b6 100644 --- a/libcons/priv.h +++ b/libcons/priv.h @@ -25,10 +25,21 @@ server. */ extern int _cons_slack; +/* If we jump down at input. */ +extern int _cons_jump_down_at_input; + +/* If we jump down at output. */ +extern int _cons_jump_down_at_output; + /* The filename of the console server. */ extern char *_cons_file; +/* Non-locking version of cons_vcons_scrollback. Does also not update + the display. */ +int _cons_vcons_scrollback (vcons_t vcons, cons_scroll_t type, float value); + + /* Called by MiG to translate ports into cons_notify_t. mutations.h arranges for this to happen for the fs_notify interfaces. */ static inline cons_notify_t diff --git a/libcons/vcons-input.c b/libcons/vcons-input.c new file mode 100644 index 00000000..83cc8846 --- /dev/null +++ b/libcons/vcons-input.c @@ -0,0 +1,54 @@ +/* vcons-input.c - Add input to a virtual console. + Copyright (C) 2002 Free Software Foundation, Inc. + Written by Marcus Brinkmann. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include <errno.h> +#include <unistd.h> + +#include "cons.h" +#include "priv.h" + +/* Enter SIZE bytes from the buffer BUF into the virtual console + VCONS. */ +error_t +cons_vcons_input (vcons_t vcons, char *buf, size_t size) +{ + int ret; + + mutex_lock (&vcons->lock); + + if (vcons->scrolling && _cons_jump_down_at_input) + _cons_vcons_scrollback (vcons, CONS_SCROLL_ABSOLUTE_LINE, 0); + + do + { + ret = write (vcons->input, buf, size); + if (ret > 0) + { + size -= ret; + buf += ret; + } + } + while (size && (ret != -1 || errno == EINTR)); + + mutex_unlock (&vcons->lock); + return 0; +} + + diff --git a/libcons/vcons-scrollback.c b/libcons/vcons-scrollback.c index cfc94458..84fef0b0 100644 --- a/libcons/vcons-scrollback.c +++ b/libcons/vcons-scrollback.c @@ -24,29 +24,43 @@ #include "cons.h" -/* Scroll back into the history of VCONS by DELTA lines. */ +/* Non-locking version of cons_vcons_scrollback. Does also not update + the display. */ int -cons_vcons_scrollback (vcons_t vcons, int delta) +_cons_vcons_scrollback (vcons_t vcons, cons_scroll_t type, float value) { int scrolling; uint32_t new_scr; - mutex_lock (&vcons->lock); - if (delta > 0 || vcons->scrolling > (uint32_t) (-delta)) + switch (type) { - new_scr = vcons->scrolling + delta; - if (new_scr > vcons->state.screen.scr_lines) - new_scr = vcons->state.screen.scr_lines; + case CONS_SCROLL_DELTA_LINES: + scrolling = vcons->scrolling + ((uint32_t) value); + break; + case CONS_SCROLL_DELTA_SCREENS: + scrolling = vcons->scrolling + + ((uint32_t) (value * vcons->state.screen.height)); + break; + case CONS_SCROLL_ABSOLUTE_LINE: + scrolling = (uint32_t) value; + break; + case CONS_SCROLL_ABSOLUTE_PERCENTAGE: + scrolling = (uint32_t) (value * vcons->state.screen.scr_lines); + break; + default: + return 0; } - else + + if (scrolling < 0) new_scr = 0; + else if (scrolling > vcons->state.screen.scr_lines) + new_scr = vcons->state.screen.scr_lines; + else + new_scr = scrolling; if (new_scr == vcons->scrolling) - { - mutex_unlock (&vcons->lock); - return 0; - } - + return 0; + scrolling = vcons->scrolling - new_scr; { uint32_t new_cur_line; @@ -114,9 +128,30 @@ cons_vcons_scrollback (vcons_t vcons, int delta) cons_vcons_set_cursor_status (vcons, CONS_CURSOR_INVISIBLE); } - cons_vcons_update (vcons); vcons->scrolling -= scrolling; - mutex_unlock (&vcons->lock); return -scrolling; } + +/* Scroll back into the history of VCONS. If TYPE is + CONS_SCROLL_DELTA_LINES, scroll up or down by VALUE lines. If TYPE + is CONS_SCROLL_DELTA_SCREENS, scroll up or down by VALUE multiples + of a screen height. If TYPE is CONS_SCROLL_ABSOLUTE_LINE, scroll to + line VALUE (where 0 is the lowest line). If TYPE is + CONS_SCROLL_ABSOLUTE_PERCENTAGE, scroll to the position determined + by VALUE, where 0 is the bottom and 1 is the top. + + The function returns the number of lines actually scrolled up or + down. */ +int +cons_vcons_scrollback (vcons_t vcons, cons_scroll_t type, float value) +{ + int ret; + + mutex_lock (&vcons->lock); + ret = _cons_vcons_scrollback (vcons, type, value); + cons_vcons_update (vcons); + mutex_unlock (&vcons->lock); + return ret; +} + |