mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-03 04:34:21 -05:00
Support insert mode
This commit is contained in:
parent
9c557407d6
commit
09031decc0
6 changed files with 79 additions and 29 deletions
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
21
tests/ref/vttest_insert/alacritty.recording
Normal file
21
tests/ref/vttest_insert/alacritty.recording
Normal file
|
@ -0,0 +1,21 @@
|
|||
[1m[7m%[27m[1m[0m
[0m[27m[24m[Jjwilm@sanctuary.local [01;32m➜ [01;32m [36m~/code/alacritty [00m [K[?1h=[?2004h[1m[31mv[0m[39m[1m[31mv[1m[31mt[0m[39m[1m[31mv[1m[31mt[1m[31mt[0m[39m[1m[31mt[1m[31me[0m[39m[1m[31me[1m[31ms[0m[39m[0m[35mv[0m[35mt[0m[35mt[0m[35me[0m[35ms[35mt[39m[?1l>[?2004l
|
||||
[0c[?1l[?3l[?4l[?5l[?6l[?7h[?8l[?40h[?45l[r[0m[2J[3;10HVT100 test program, version 2.7 (20140305)[4;10H[5;10HChoose test type:
|
||||
[6;1H[0J
|
||||
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
|
||||
[2J[?3l[2J[1;1H[1;1HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA[2;1HBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB[3;1HCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC[4;1HDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD[5;1HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE[6;1HFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF[7;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SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS[20;1HTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT[21;1HUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU[22;1HVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV[23;1HWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW[24;1HXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX[4;1HScreen accordion test (Insert & Delete Line). Push <RETURN>
|
||||
M[2K[2;23r[?6h[1;1H[1L[1M[2L[2M[3L[3M[4L[4M[5L[5M[6L[6M[7L[7M[8L[8M[9L[9M[10L[10M[11L[11M[12L[12M[13L[13M[14L[14M[15L[15M[16L[16M[17L[17M[18L[18M[19L[19M[20L[20M[21L[21M[22L[22M[23L[23M[24L[24M[?6l[r[2;1HTop line: A's, bottom line: X's, this line, nothing more. Push <RETURN>
|
||||
[2;1H[0J[1;2HB[1D[4h******************************************************************************[4l[4;1HTest of 'Insert Mode'. The top line should be 'A*** ... ***B'. Push <RETURN>
|
1
tests/ref/vttest_insert/grid.json
Normal file
1
tests/ref/vttest_insert/grid.json
Normal file
File diff suppressed because one or more lines are too long
1
tests/ref/vttest_insert/size.json
Normal file
1
tests/ref/vttest_insert/size.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"width":1124.0,"height":676.0,"cell_width":14.0,"cell_height":28.0}
|
Loading…
Reference in a new issue