1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

Support insert mode

This commit is contained in:
Joe Wilm 2017-04-30 22:10:38 -07:00 committed by Joe Wilm
parent 9c557407d6
commit 09031decc0
6 changed files with 79 additions and 29 deletions

View file

@ -275,6 +275,13 @@ pub enum Mode {
/// * resets DECLRMM to unavailable
/// * clears data from the status line (if set to host-writable)
DECCOLM = 3,
/// IRM Insert Mode
///
/// NB should be part of non-private mode enum
///
/// * `CSI 4 h` change to insert mode
/// * `CSI 4 l` reset to replacement mode
Insert = 4,
/// ?6
Origin = 6,
/// ?7
@ -322,6 +329,7 @@ impl Mode {
})
} else {
Some(match num {
4 => Mode::Insert,
20 => Mode::LineFeedNewLine,
_ => return None
})

View file

@ -252,17 +252,18 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
pub mod mode {
bitflags! {
pub flags TermMode: u16 {
const SHOW_CURSOR = 0b0000000001,
const APP_CURSOR = 0b0000000010,
const APP_KEYPAD = 0b0000000100,
const MOUSE_REPORT_CLICK = 0b0000001000,
const BRACKETED_PASTE = 0b0000010000,
const SGR_MOUSE = 0b0000100000,
const MOUSE_MOTION = 0b0001000000,
const LINE_WRAP = 0b0010000000,
const LINE_FEED_NEW_LINE = 0b0100000000,
const ORIGIN = 0b1000000000,
const ANY = 0b1111111111,
const SHOW_CURSOR = 0b00000000001,
const APP_CURSOR = 0b00000000010,
const APP_KEYPAD = 0b00000000100,
const MOUSE_REPORT_CLICK = 0b00000001000,
const BRACKETED_PASTE = 0b00000010000,
const SGR_MOUSE = 0b00000100000,
const MOUSE_MOTION = 0b00001000000,
const LINE_WRAP = 0b00010000000,
const LINE_FEED_NEW_LINE = 0b00100000000,
const ORIGIN = 0b01000000000,
const INSERT = 0b10000000000,
const ANY = 0b11111111111,
const NONE = 0,
}
}
@ -1061,28 +1062,43 @@ impl ansi::Handler for Term {
{
// Number of cells the char will occupy
let width = c.width();
if let Some(width) = c.width() {
// Sigh, borrowck making us check the width twice. Hopefully the
// optimizer can fix it.
let num_cols = self.grid.num_cols();
{
// If in insert mode, first shift cells to the right.
if self.mode.contains(mode::INSERT) && self.cursor.point.col + width < num_cols {
let line = self.cursor.point.line; // borrowck
let col = self.cursor.point.col;
let line = &mut self.grid[line];
// Sigh, borrowck making us check the width twice. Hopefully the
// optimizer can fix it.
{
let cell = &mut self.grid[&self.cursor.point];
*cell = self.cursor.template;
cell.c = self.cursor.charsets[self.active_charset].map(c);
let src = line[col..].as_ptr();
let dst = line[(col + width)..].as_mut_ptr();
unsafe {
// memmove
ptr::copy(src, dst, (num_cols - col - width).0);
}
}
// Handle wide chars
if let Some(2) = width {
cell.flags.insert(cell::WIDE_CHAR);
let cell = &mut self.grid[&self.cursor.point];
*cell = self.cursor.template;
cell.c = self.cursor.charsets[self.active_charset].map(c);
// Handle wide chars
if width == 2 {
cell.flags.insert(cell::WIDE_CHAR);
}
}
}
// Set spacer cell for wide chars.
if let Some(2) = width {
if self.cursor.point.col + 1 < self.grid.num_cols() {
self.cursor.point.col += 1;
let spacer = &mut self.grid[&self.cursor.point];
*spacer = self.cursor.template;
spacer.flags.insert(cell::WIDE_CHAR_SPACER);
// Set spacer cell for wide chars.
if width == 2 {
if self.cursor.point.col + 1 < num_cols {
self.cursor.point.col += 1;
let spacer = &mut self.grid[&self.cursor.point];
*spacer = self.cursor.template;
spacer.flags.insert(cell::WIDE_CHAR_SPACER);
}
}
}
}
@ -1584,6 +1600,7 @@ impl ansi::Handler for Term {
ansi::Mode::LineFeedNewLine => self.mode.insert(mode::LINE_FEED_NEW_LINE),
ansi::Mode::Origin => self.mode.insert(mode::ORIGIN),
ansi::Mode::DECCOLM => self.deccolm(),
ansi::Mode::Insert => self.mode.insert(mode::INSERT), // heh
_ => {
debug!(".. ignoring set_mode");
}
@ -1609,6 +1626,7 @@ impl ansi::Handler for Term {
ansi::Mode::LineFeedNewLine => self.mode.remove(mode::LINE_FEED_NEW_LINE),
ansi::Mode::Origin => self.mode.remove(mode::ORIGIN),
ansi::Mode::DECCOLM => self.deccolm(),
ansi::Mode::Insert => self.mode.remove(mode::INSERT),
_ => {
debug!(".. ignoring unset_mode");
}

View file

@ -37,6 +37,7 @@ ref_tests! {
vim_large_window_scroll
vim_simple_edit
vttest_cursor_movement_1
vttest_insert
vttest_origin_mode_1
vttest_origin_mode_2
vttest_scroll

View file

@ -0,0 +1,21 @@
% jwilm@sanctuary.local ➜  ~/code/alacritty  [?1h=[?2004hvvtvttteesvttest[?1l>[?2004l
[?1l[?3l[?4l[?5l[?6l[?7h[?8l[?40h[?45lVT100 test program, version 2.7 (20140305)Choose test type:

0. Exit
1. Test of cursor movements
2. Test of screen features
3. Test of character sets
4. Test of double-sized characters
5. Test of keyboard
6. Test of terminal reports
7. Test of VT52 mode
8. Test of VT102 features (Insert/Delete Char/Line)
9. Test of known bugs
10. Test of reset and self-test
11. Test non-VT100 (e.g., VT220, XTERM) terminals
12. Modify test-parameters
Enter choice number (0 - 12): 8
[?3lAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG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TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXScreen accordion test (Insert & Delete Line). Push <RETURN>
M[?6h[?6lTop line: A's, bottom line: X's, this line, nothing more. Push <RETURN>
B******************************************************************************Test of 'Insert Mode'. The top line should be 'A*** ... ***B'. Push <RETURN>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1 @@
{"width":1124.0,"height":676.0,"cell_width":14.0,"cell_height":28.0}