aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-12 05:47:32 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-12 05:51:17 -0500
commit28eea9f6a837dad5febfe9b021b7070e96b286f9 (patch)
treec48d13955c045b892b95f6e652f8be22938705d1 /src
parentbdda29c8e82e22bf49b5588f341549d3f94d6d30 (diff)
downloadvt100-rust-28eea9f6a837dad5febfe9b021b7070e96b286f9.tar.gz
vt100-rust-28eea9f6a837dad5febfe9b021b7070e96b286f9.zip
remove parser.screen_mut
it's easier to reason about if you are only able to get an immutable reference to the internal screen. this also required changing the api for bells.
Diffstat (limited to 'src')
-rw-r--r--src/parser.rs26
-rw-r--r--src/screen.rs74
2 files changed, 46 insertions, 54 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 07ee7c9..613e18e 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -26,17 +26,31 @@ impl Parser {
}
}
+ /// Resizes the terminal.
+ pub fn set_size(&mut self, rows: u16, cols: u16) {
+ self.screen.set_size(rows, cols);
+ }
+
+ /// Scrolls to the given position in the scrollback.
+ ///
+ /// This position indicates the offset from the top of the screen, and
+ /// should be `0` to put the normal screen in view.
+ ///
+ /// This affects the return values of methods called on `parser.screen()`:
+ /// for instance, `parser.screen().cell(0, 0)` will return the top left
+ /// corner of the screen after taking the scrollback offset into account.
+ /// It does not affect `parser.process()` at all.
+ ///
+ /// The value given will be clamped to the actual size of the scrollback.
+ pub fn set_scrollback(&mut self, rows: usize) {
+ self.screen.set_scrollback(rows);
+ }
+
/// Returns a reference to a `Screen` object containing the terminal
/// state.
pub fn screen(&self) -> &crate::screen::Screen {
&self.screen
}
-
- /// Returns a mutable reference to a `Screen` object containing the
- /// terminal state.
- pub fn screen_mut(&mut self) -> &mut crate::screen::Screen {
- &mut self.screen
- }
}
impl Default for Parser {
diff --git a/src/screen.rs b/src/screen.rs
index 36a47c4..c2eaf0e 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -5,12 +5,6 @@ use unicode_width::UnicodeWidthChar as _;
const DEFAULT_MULTI_PARAMS: &[i64] = &[0];
#[derive(enumset::EnumSetType, Debug)]
-enum Output {
- AudibleBell,
- VisualBell,
-}
-
-#[derive(enumset::EnumSetType, Debug)]
enum Mode {
ApplicationKeypad,
ApplicationCursor,
@@ -84,10 +78,12 @@ pub struct Screen {
title: String,
icon_name: String,
- outputs: enumset::EnumSet<Output>,
modes: enumset::EnumSet<Mode>,
mouse_protocol_mode: MouseProtocolMode,
mouse_protocol_encoding: MouseProtocolEncoding,
+
+ audible_bell_count: usize,
+ visual_bell_count: usize,
}
impl Screen {
@@ -105,15 +101,16 @@ impl Screen {
title: String::default(),
icon_name: String::default(),
- outputs: enumset::EnumSet::default(),
modes: enumset::EnumSet::default(),
mouse_protocol_mode: MouseProtocolMode::default(),
mouse_protocol_encoding: MouseProtocolEncoding::default(),
+
+ audible_bell_count: 0,
+ visual_bell_count: 0,
}
}
- /// Resizes the terminal.
- pub fn set_size(&mut self, rows: u16, cols: u16) {
+ pub(crate) fn set_size(&mut self, rows: u16, cols: u16) {
self.grid.set_size(crate::grid::Size { rows, cols });
self.alternate_grid
.set_size(crate::grid::Size { rows, cols });
@@ -135,18 +132,7 @@ impl Screen {
self.grid().scrollback()
}
- /// Scrolls to the given position in the scrollback.
- ///
- /// This position indicates the offset from the top of the screen, and
- /// should be `0` to put the normal screen in view.
- ///
- /// This affects the return values of methods called on `parser.screen()`:
- /// for instance, `parser.screen().cell(0, 0)` will return the top left
- /// corner of the screen after taking the scrollback offset into account.
- /// It does not affect `parser.process()` at all.
- ///
- /// The value given will be clamped to the actual size of the scrollback.
- pub fn set_scrollback(&mut self, rows: usize) {
+ pub(crate) fn set_scrollback(&mut self, rows: usize) {
self.grid_mut().set_scrollback(rows);
}
@@ -321,16 +307,20 @@ impl Screen {
&self.icon_name
}
- /// Returns whether an audible bell has occurred since the last time this
- /// method was called.
- pub fn check_audible_bell(&mut self) -> bool {
- self.check_output(Output::AudibleBell)
+ /// Returns the total number of audible bells seen so far.
+ ///
+ /// Typically you would store this number after each call to `process`,
+ /// and trigger an audible bell whenever it changes.
+ pub fn audible_bell_count(&self) -> usize {
+ self.audible_bell_count
}
- /// Returns whether an visual bell has occurred since the last time this
- /// method was called.
- pub fn check_visual_bell(&mut self) -> bool {
- self.check_output(Output::VisualBell)
+ /// Returns the total number of visual bells seen so far.
+ ///
+ /// Typically you would store this number after each call to `process`,
+ /// and trigger an visual bell whenever it changes.
+ pub fn visual_bell_count(&self) -> usize {
+ self.visual_bell_count
}
/// Returns whether the terminal should be in application keypad mode.
@@ -413,20 +403,6 @@ impl Screen {
self.attrs = self.saved_attrs;
}
- fn set_output(&mut self, output: Output) {
- self.outputs.insert(output);
- }
-
- fn clear_output(&mut self, output: Output) {
- self.outputs.remove(output);
- }
-
- fn check_output(&mut self, output: Output) -> bool {
- let ret = self.outputs.contains(output);
- self.clear_output(output);
- ret
- }
-
fn set_mode(&mut self, mode: Mode) {
self.modes.insert(mode);
}
@@ -523,7 +499,7 @@ impl Screen {
// control codes
fn bel(&mut self) {
- self.set_output(Output::AudibleBell);
+ self.audible_bell_count += 1;
}
fn bs(&mut self) {
@@ -579,20 +555,22 @@ impl Screen {
// ESC c
fn ris(&mut self) {
- let outputs = self.outputs;
let title = self.title.clone();
let icon_name = self.icon_name.clone();
+ let audible_bell_count = self.audible_bell_count;
+ let visual_bell_count = self.visual_bell_count;
*self = Self::new(self.grid.size(), self.grid.scrollback_len());
- self.outputs = outputs;
self.title = title;
self.icon_name = icon_name;
+ self.audible_bell_count = audible_bell_count;
+ self.visual_bell_count = visual_bell_count;
}
// ESC g
fn vb(&mut self) {
- self.set_output(Output::VisualBell);
+ self.visual_bell_count += 1;
}
// csi codes