first pass of merging in warp (doesn't build)
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2020 The Alacritty Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -1,14 +1,19 @@
|
||||
// The code in this file is adapted from the vte crate (an Alacritty project)
|
||||
// under the Apache license; see: crates/warp_terminal/src/model/LICENSE-ALACRITTY.
|
||||
|
||||
//! This module exports abstractions for parameters of control sequence actions;
|
||||
//! e.g. actions to be executed after receiving a control sequence from the pty.
|
||||
//!
|
||||
//! Examples of such actions include repositioning the cursor, changing text
|
||||
//! styles, and setting terminal modes.
|
||||
use std::convert::TryFrom;
|
||||
use std::{iter, str};
|
||||
|
||||
use anyhow::bail;
|
||||
use get_size::GetSize;
|
||||
use log::trace;
|
||||
use pathfinder_color::ColorU;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{convert::TryFrom, iter, str};
|
||||
use thiserror::Error;
|
||||
use vte::ParamsIter;
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use std::{
|
||||
fmt::{self, Display, Formatter},
|
||||
ops::{Add, AddAssign, Range, Sub, SubAssign},
|
||||
};
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::ops::{Add, AddAssign, Range, Sub, SubAssign};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ use std::collections::HashMap;
|
||||
use galaxyui::keymap::Keystroke;
|
||||
use galaxyui::platform::OperatingSystem;
|
||||
use lazy_static::lazy_static;
|
||||
use galaxyui_core::keymap::Keystroke;
|
||||
use galaxyui_core::platform::OperatingSystem;
|
||||
|
||||
use super::{
|
||||
mouse::{MouseAction, MouseButton, MouseState},
|
||||
TermMode,
|
||||
};
|
||||
use super::mouse::{MouseAction, MouseButton, MouseState};
|
||||
use super::TermMode;
|
||||
|
||||
mod kitty_keyboard_protocol;
|
||||
|
||||
@@ -249,6 +249,7 @@ impl<T: ModeProvider> ToEscapeSequence<T> for KeystrokeWithDetails<'_> {
|
||||
.or_else(|| keystroke_to_c0_control_code(keystroke, mode_provider))
|
||||
.or_else(|| cursor_movement_keystroke_to_escape_sequence(keystroke, mode_provider))
|
||||
.or_else(|| meta_keystroke_to_escape_sequence(keystroke, mode_provider))
|
||||
.or_else(|| backspace_keystroke_to_escape_sequence(keystroke))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,6 +551,9 @@ fn cursor_movement_keystroke_to_escape_sequence(
|
||||
/// further than a HashMap.
|
||||
fn map_special_key_to_bytes(key: &str) -> Option<&[u8]> {
|
||||
match key {
|
||||
"enter" | "numpadenter" => Some("\r".as_bytes()),
|
||||
"tab" => Some("\t".as_bytes()),
|
||||
"escape" => Some("\x1b".as_bytes()),
|
||||
"backspace" => Some("\x7f".as_bytes()),
|
||||
"insert" => Some("\x1b[2~".as_bytes()),
|
||||
"delete" => Some("\x1b[3~".as_bytes()),
|
||||
@@ -592,6 +596,19 @@ fn meta_keystroke_to_escape_sequence(
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns DEL (0x7f) for an unmodified or Shift-only Backspace.
|
||||
/// Guards against winit on Windows reporting `\x08` (Ctrl+H) for Shift+Backspace,
|
||||
/// which readline-style TUIs interpret as `backward-kill-word`. See GH#11342.
|
||||
fn backspace_keystroke_to_escape_sequence(keystroke: &Keystroke) -> Option<Vec<u8>> {
|
||||
if keystroke.ctrl || keystroke.alt || keystroke.meta || keystroke.cmd {
|
||||
return None;
|
||||
}
|
||||
match keystroke.key.as_str() {
|
||||
"backspace" => Some(vec![C0::DEL]),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "escape_sequences_test.rs"]
|
||||
#[path = "escape_sequences_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use galaxyui::keymap::Keystroke;
|
||||
use galaxyui::platform::keyboard::KeyCode;
|
||||
use galaxyui::platform::OperatingSystem;
|
||||
use galaxyui_core::keymap::Keystroke;
|
||||
use galaxyui_core::platform::keyboard::KeyCode;
|
||||
use galaxyui_core::platform::OperatingSystem;
|
||||
|
||||
use super::{ModeProvider, TermMode};
|
||||
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
use galaxyui::keymap::Keystroke;
|
||||
use galaxyui::platform::OperatingSystem;
|
||||
|
||||
use crate::model::{
|
||||
indexing::Point,
|
||||
mouse::{MouseAction, MouseButton, MouseState},
|
||||
TermMode,
|
||||
};
|
||||
use galaxyui_core::keymap::Keystroke;
|
||||
use galaxyui_core::platform::OperatingSystem;
|
||||
|
||||
use super::*;
|
||||
use crate::model::indexing::Point;
|
||||
use crate::model::mouse::{MouseAction, MouseButton, MouseState};
|
||||
use crate::model::TermMode;
|
||||
|
||||
fn validate_keystroke_test_cases<T: ModeProvider>(
|
||||
test_cases: &[(Keystroke, Vec<u8>)],
|
||||
@@ -60,6 +57,19 @@ fn test_keystroke_to_c0_control_code() {
|
||||
validate_keystroke_test_cases(test_cases, &terminal_model_mock);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shift_backspace_emits_del_sequence() {
|
||||
// Regression test: Shift+Backspace must emit DEL (0x7f), not BS (0x08).
|
||||
// 0x08 is Ctrl+H, which readline-style TUIs interpret as backward-kill-word.
|
||||
let test_cases: &[(Keystroke, Vec<u8>)] = &[
|
||||
(Keystroke::parse("backspace").unwrap(), vec![C0::DEL]),
|
||||
(Keystroke::parse("shift-backspace").unwrap(), vec![C0::DEL]),
|
||||
];
|
||||
|
||||
let terminal_model_mock = TerminalModelMock::new();
|
||||
validate_keystroke_test_cases(test_cases, &terminal_model_mock);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mouse_actions_to_escape_sequence() {
|
||||
// Validating we produce the correct escape sequences.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,6 @@
|
||||
// The code in this file is adapted from the alacritty_terminal crate under the
|
||||
// Apache license; see: crates/warp_terminal/src/model/LICENSE-ALACRITTY.
|
||||
|
||||
use std::boxed::Box;
|
||||
|
||||
use bitflags::bitflags;
|
||||
@@ -384,5 +387,5 @@ impl From<char> for Cell {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "cell_test.rs"]
|
||||
#[path = "cell_tests.rs"]
|
||||
mod tests;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
use super::{Cell, LineLength};
|
||||
// The code in this file is adapted from the alacritty_terminal crate under the
|
||||
// Apache license; see: crates/warp_terminal/src/model/LICENSE-ALACRITTY.
|
||||
|
||||
use crate::model::{
|
||||
char_or_str::CharOrStr,
|
||||
grid::{
|
||||
cell::{Flags, MAX_GRAPHEME_BYTES},
|
||||
row::Row,
|
||||
},
|
||||
};
|
||||
use super::{Cell, LineLength};
|
||||
use crate::model::char_or_str::CharOrStr;
|
||||
use crate::model::grid::cell::{Flags, MAX_GRAPHEME_BYTES};
|
||||
use crate::model::grid::row::Row;
|
||||
|
||||
#[test]
|
||||
fn verify_cell_size() {
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
// The code in this file is adapted from the alacritty_terminal crate under the
|
||||
// Apache license; see: crates/warp_terminal/src/model/LICENSE-ALACRITTY.
|
||||
|
||||
use super::{Cell, LineLength};
|
||||
use crate::model::char_or_str::CharOrStr;
|
||||
use crate::model::grid::cell::{Flags, MAX_GRAPHEME_BYTES};
|
||||
use crate::model::grid::row::Row;
|
||||
|
||||
#[test]
|
||||
fn verify_cell_size() {
|
||||
// If this test fails, then something has changed about Cell that alters its memory layout and
|
||||
// causes it to be a different size than expected. Verify carefully if that is expected before
|
||||
// updating the constant value.
|
||||
const EXPECTED_CELL_SIZE_IN_BYTES: usize = 24;
|
||||
|
||||
assert_eq!(std::mem::size_of::<Cell>(), EXPECTED_CELL_SIZE_IN_BYTES);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_length_works() {
|
||||
let mut row = Row::new(10);
|
||||
row[5].c = 'a';
|
||||
|
||||
assert_eq!(row.line_length(), 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_length_works_with_wrapline() {
|
||||
let mut row = Row::new(10);
|
||||
row[9].flags.insert(super::Flags::WRAPLINE);
|
||||
|
||||
assert_eq!(row.line_length(), 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_length_works_with_empty_line() {
|
||||
let mut row = Row::new(1);
|
||||
row.shrink(0);
|
||||
assert_eq!(row.line_length(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_contains_cell_decorations() {
|
||||
assert!(Flags::UNDERLINE.intersects(Flags::CELL_DECORATIONS));
|
||||
assert!(Flags::STRIKEOUT.intersects(Flags::CELL_DECORATIONS));
|
||||
assert!(Flags::DOUBLE_UNDERLINE.intersects(Flags::CELL_DECORATIONS));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_zerowidth_caps_accumulated_grapheme() {
|
||||
// A ZWJ (U+200D) is three bytes in UTF-8. Push enough of them to go
|
||||
// well past `MAX_GRAPHEME_BYTES`, and verify that the accumulated
|
||||
// content stops growing at the cap.
|
||||
let mut cell = Cell {
|
||||
c: 'e',
|
||||
..Cell::default()
|
||||
};
|
||||
let zwj = '\u{200D}';
|
||||
let zwj_bytes = zwj.len_utf8();
|
||||
let pushes = (MAX_GRAPHEME_BYTES * 10) / zwj_bytes;
|
||||
for _ in 0..pushes {
|
||||
cell.push_zerowidth(zwj, /* log_long_grapheme_warnings */ true);
|
||||
}
|
||||
|
||||
let CharOrStr::Str(content) = cell.raw_content() else {
|
||||
panic!("cell should have accumulated zero-width content as a string");
|
||||
};
|
||||
// The stored content is "base char + N zero-width chars". The total
|
||||
// length in bytes must fit within the cap.
|
||||
assert!(
|
||||
content.len() <= MAX_GRAPHEME_BYTES,
|
||||
"expected stored content length {} to be <= cap {}",
|
||||
content.len(),
|
||||
MAX_GRAPHEME_BYTES,
|
||||
);
|
||||
// We also want the cap to actually be approached: the stored content
|
||||
// should contain many zero-width characters and not have been truncated
|
||||
// early.
|
||||
let zero_width_bytes = content.len() - 'e'.len_utf8();
|
||||
let zero_width_count = zero_width_bytes / zwj_bytes;
|
||||
assert!(
|
||||
zero_width_count >= 80,
|
||||
"expected at least 80 zero-width chars to fit, got {zero_width_count}",
|
||||
);
|
||||
assert!(content.starts_with('e'));
|
||||
assert!(content[1..].chars().all(|c| c == zwj));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_zerowidth_seeds_base_char_on_first_push() {
|
||||
// Before any zero-width char is pushed, the cell's raw content is just
|
||||
// the base char. After the first push, the content becomes a string
|
||||
// consisting of the base char plus the pushed zero-width char.
|
||||
let mut cell = Cell {
|
||||
c: 'x',
|
||||
..Cell::default()
|
||||
};
|
||||
assert_eq!(cell.raw_content(), CharOrStr::Char('x'));
|
||||
|
||||
cell.push_zerowidth('\u{0301}', /* log_long_grapheme_warnings */ true);
|
||||
assert_eq!(cell.raw_content(), CharOrStr::Str("x\u{0301}"));
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
// The code in this file is adapted from the alacritty_terminal crate under the
|
||||
// Apache license; see: crates/warp_terminal/src/model/LICENSE-ALACRITTY.
|
||||
|
||||
/// Grid dimensions.
|
||||
pub trait Dimensions {
|
||||
/// Total number of lines in the buffer, this includes scrollback and visible lines.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use std::{
|
||||
collections::{btree_map, BTreeMap},
|
||||
ops::RangeFrom,
|
||||
};
|
||||
use std::collections::{btree_map, BTreeMap};
|
||||
use std::ops::RangeFrom;
|
||||
|
||||
use get_size::GetSize;
|
||||
use string_offset::ByteOffset;
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
//! Structures for storing the grid contents in a flat buffer.
|
||||
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
ops::{Index, Range},
|
||||
};
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::{Index, Range};
|
||||
|
||||
use get_size::GetSize;
|
||||
use string_offset::ByteOffset;
|
||||
|
||||
use crate::model::char_or_str::CharOrStr;
|
||||
|
||||
use super::grapheme::Grapheme;
|
||||
use crate::model::char_or_str::CharOrStr;
|
||||
|
||||
/// A helper structure that wraps the underlying grid content and provides
|
||||
/// higher-level APIs for accessing the data.
|
||||
|
||||
@@ -2,12 +2,9 @@ use std::num::NonZeroU16;
|
||||
|
||||
use string_offset::ByteOffset;
|
||||
|
||||
use crate::model::{
|
||||
char_or_str::CharOrStr,
|
||||
grid::cell::{self, Cell},
|
||||
};
|
||||
|
||||
use super::index::GraphemeInfo;
|
||||
use crate::model::char_or_str::CharOrStr;
|
||||
use crate::model::grid::cell::{self, Cell};
|
||||
|
||||
/// A grapheme is a collection of [`char`]s that, together, represent a single
|
||||
/// "user-perceived character".
|
||||
|
||||
@@ -19,20 +19,18 @@
|
||||
//! in the entire flat storage implementation that should be keyed on anything
|
||||
//! other than content offsets is the [`rows`](Index::rows) field of the index.
|
||||
|
||||
use std::{
|
||||
collections::{BTreeMap, VecDeque},
|
||||
num::NonZeroU16,
|
||||
ops::Range,
|
||||
};
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
use std::num::NonZeroU16;
|
||||
use std::ops::Range;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use get_size::GetSize;
|
||||
use string_offset::ByteOffset;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::model::{grid::CellType, Point};
|
||||
|
||||
use super::grapheme::Grapheme;
|
||||
use crate::model::grid::CellType;
|
||||
use crate::model::Point;
|
||||
|
||||
#[derive(Debug, Clone, GetSize)]
|
||||
/// A structure to help index into a grid's content by (soft-wrapped) row.
|
||||
@@ -101,13 +99,13 @@ impl Index {
|
||||
pub fn rebuild(old_index: &Index, columns: usize) -> Self {
|
||||
let mut index = Self::new(columns, Some(old_index.len()));
|
||||
// Update the content length to be the start offset of the first row,
|
||||
// to ensure we properly handle resizing after truncation.
|
||||
// or preserve the old content offset if no rows remain, to ensure we
|
||||
// properly handle resizing after truncation.
|
||||
index.content_len = old_index
|
||||
.rows
|
||||
.front()
|
||||
.map(|entry| entry.content_offset)
|
||||
.unwrap_or_default()
|
||||
.as_usize();
|
||||
.map(|entry| entry.content_offset.as_usize())
|
||||
.unwrap_or(old_index.content_len);
|
||||
|
||||
let mut entry_builder = EntryBuilder::new();
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::num::NonZeroU16;
|
||||
|
||||
use crate::model::grid::FlatStorage;
|
||||
|
||||
use super::*;
|
||||
use crate::model::grid::FlatStorage;
|
||||
|
||||
const ASCII_GRAPHEME_INFO: GraphemeInfo = GraphemeInfo {
|
||||
cell_width: 1,
|
||||
@@ -292,7 +291,6 @@ fn test_cell_type() {
|
||||
}
|
||||
|
||||
mod offset_point_conversion {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_normal_cell() {
|
||||
|
||||
@@ -36,10 +36,10 @@ use itertools::Itertools;
|
||||
use string_offset::ByteOffset;
|
||||
use style::BgAndStyle;
|
||||
|
||||
use super::row::Row;
|
||||
use super::{cell, CellType};
|
||||
use crate::model::{ansi, Point};
|
||||
|
||||
use super::{cell, row::Row, CellType};
|
||||
|
||||
const DEFAULT_FG_COLOR: ansi::Color = ansi::Color::Named(ansi::NamedColor::Foreground);
|
||||
|
||||
/// A grid storage implementation that stores content in a flat buffer.
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
use itertools::Itertools;
|
||||
use testing::{assert_rows_equal, ToRows as _};
|
||||
|
||||
use crate::model::{
|
||||
char_or_str::CharOrStr,
|
||||
grid::cell::{Cell, Flags},
|
||||
};
|
||||
|
||||
use super::*;
|
||||
use crate::model::char_or_str::CharOrStr;
|
||||
use crate::model::grid::cell::{Cell, Flags};
|
||||
|
||||
#[test]
|
||||
fn test_row_iteration() {
|
||||
@@ -254,3 +251,27 @@ fn test_clear_after_truncate_front() {
|
||||
'2'
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clear_after_truncate_front_then_resize_and_push_does_not_panic() {
|
||||
let old_cols = 20;
|
||||
let new_cols = 21;
|
||||
let initial_content = "abcdefghijklmnopqrst\n".repeat(100);
|
||||
let rows = initial_content.as_str().to_rows(old_cols);
|
||||
|
||||
let mut storage = FlatStorage::new(old_cols, Some(1), None);
|
||||
storage.push_rows(&rows);
|
||||
assert_eq!(storage.total_rows(), 1);
|
||||
|
||||
storage.clear();
|
||||
storage.set_columns(new_cols);
|
||||
|
||||
let new_rows = "new output\n".to_rows(new_cols);
|
||||
storage.push_rows(&new_rows);
|
||||
|
||||
let row = storage
|
||||
.rows_from(0)
|
||||
.next()
|
||||
.expect("should materialize a row after clearing and resizing storage");
|
||||
assert_eq!(row[0].c, 'n');
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::model::grid::{
|
||||
cell::{Cell, Flags},
|
||||
row::Row,
|
||||
};
|
||||
|
||||
use super::{grapheme::Grapheme, style::BgAndStyle, EndOfPromptMarker, FlatStorage};
|
||||
use super::grapheme::Grapheme;
|
||||
use super::style::BgAndStyle;
|
||||
use super::{EndOfPromptMarker, FlatStorage};
|
||||
use crate::model::grid::cell::{Cell, Flags};
|
||||
use crate::model::grid::row::Row;
|
||||
|
||||
/// An iterator over [`Row`]s in the grid.
|
||||
///
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
use get_size::GetSize;
|
||||
|
||||
use crate::model::{ansi, grid::cell};
|
||||
|
||||
use super::attribute_map::AttributeMap;
|
||||
use crate::model::ansi;
|
||||
use crate::model::grid::cell;
|
||||
|
||||
/// A map that holds foreground color information.
|
||||
pub type FgColorMap = AttributeMap<ansi::Color>;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use unicode_segmentation::UnicodeSegmentation as _;
|
||||
|
||||
use crate::model::grid::{cell::Flags, row::Row};
|
||||
|
||||
use super::{grapheme::Grapheme, FlatStorage};
|
||||
use super::grapheme::Grapheme;
|
||||
use super::FlatStorage;
|
||||
use crate::model::grid::cell::Flags;
|
||||
use crate::model::grid::row::Row;
|
||||
|
||||
pub fn assert_rows_equal(actual: &[Row], expected: &[Row]) {
|
||||
assert_eq!(
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// The code in this file is adapted from the alacritty_terminal crate under the
|
||||
// Apache license; see: crates/warp_terminal/src/model/LICENSE-ALACRITTY.
|
||||
|
||||
//! Defines the Row type which makes up lines in the grid.
|
||||
use std::cmp::{max, min};
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::ops::{Range, RangeFrom, RangeFull, RangeTo, RangeToInclusive};
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use std::ops::{Index, IndexMut, Range, RangeFrom, RangeFull, RangeTo, RangeToInclusive};
|
||||
use std::{ptr, slice};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::ops::{Add, AddAssign, Range, Sub, SubAssign};
|
||||
|
||||
use galaxyui::units::Lines;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use galaxyui_core::units::Lines;
|
||||
|
||||
use super::grid::Dimensions;
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// The code in this file is adapted from the alacritty_terminal crate under the
|
||||
// Apache license; see: crates/warp_terminal/src/model/LICENSE-ALACRITTY.
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
||||
bitflags! {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use galaxyui::event::ModifiersState;
|
||||
use galaxyui_core::event::ModifiersState;
|
||||
|
||||
use super::indexing::Point;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user