Skip to content

Commit b4fe182

Browse files
committed
Make EscapeSequenceOffsetsIterator pub, add fns to get indices
1 parent b7e44c7 commit b4fe182

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/vscreen.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ fn join(
285285

286286
/// A range of indices for a raw ANSI escape sequence.
287287
#[derive(Debug, PartialEq)]
288-
enum EscapeSequenceOffsets {
288+
pub enum EscapeSequenceOffsets {
289289
Text {
290290
start: usize,
291291
end: usize,
@@ -320,14 +320,40 @@ enum EscapeSequenceOffsets {
320320
},
321321
}
322322

323+
impl EscapeSequenceOffsets {
324+
/// Returns the byte-index of the first character in the escape sequence.
325+
pub fn index_of_start(&self) -> usize {
326+
use EscapeSequenceOffsets::*;
327+
match self {
328+
Text { start, .. } => *start,
329+
Unknown { start, .. } => *start,
330+
NF { start_sequence, .. } => *start_sequence,
331+
OSC { start_sequence, .. } => *start_sequence,
332+
CSI { start_sequence, .. } => *start_sequence,
333+
}
334+
}
335+
336+
/// Returns the byte-index past the last character in the escape sequence.
337+
pub fn index_past_end(&self) -> usize {
338+
use EscapeSequenceOffsets::*;
339+
match self {
340+
Text { end, .. } => *end,
341+
Unknown { end, .. } => *end,
342+
NF { end, .. } => *end,
343+
OSC { end, .. } => *end,
344+
CSI { end, .. } => *end,
345+
}
346+
}
347+
}
348+
323349
/// An iterator over the offests of ANSI/VT escape sequences within a string.
324350
///
325351
/// ## Example
326352
///
327353
/// ```ignore
328354
/// let iter = EscapeSequenceOffsetsIterator::new("\x1B[33mThis is yellow text.\x1B[m");
329355
/// ```
330-
struct EscapeSequenceOffsetsIterator<'a> {
356+
pub struct EscapeSequenceOffsetsIterator<'a> {
331357
text: &'a str,
332358
chars: Peekable<CharIndices<'a>>,
333359
}

0 commit comments

Comments
 (0)