-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
performance improvement/ fix text wrapper
- Loading branch information
Showing
13 changed files
with
283 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
lumni/src/apps/builtin/llm/prompt/src/tui/window/text_document/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
lumni/src/apps/builtin/llm/prompt/src/tui/window/text_document/simple_string.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use std::borrow::Cow; | ||
use std::ops::Deref; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum SimpleString { | ||
Owned(String), | ||
Borrowed(&'static str), | ||
} | ||
|
||
impl SimpleString { | ||
pub fn new<S: Into<SimpleString>>(s: S) -> Self { | ||
s.into() | ||
} | ||
|
||
pub fn as_str(&self) -> &str { | ||
match self { | ||
SimpleString::Owned(s) => s, | ||
SimpleString::Borrowed(s) => s, | ||
} | ||
} | ||
|
||
pub fn into_owned(self) -> String { | ||
match self { | ||
SimpleString::Owned(s) => s, | ||
SimpleString::Borrowed(s) => s.to_owned(), | ||
} | ||
} | ||
|
||
pub fn from_str(s: &str) -> Self { | ||
SimpleString::Owned(s.to_owned()) | ||
} | ||
|
||
pub fn from_string(s: String) -> Self { | ||
SimpleString::Owned(s) | ||
} | ||
} | ||
|
||
impl From<String> for SimpleString { | ||
fn from(s: String) -> Self { | ||
SimpleString::Owned(s) | ||
} | ||
} | ||
|
||
impl From<&'static str> for SimpleString { | ||
fn from(s: &'static str) -> Self { | ||
SimpleString::Borrowed(s) | ||
} | ||
} | ||
|
||
impl From<Cow<'static, str>> for SimpleString { | ||
fn from(s: Cow<'static, str>) -> Self { | ||
match s { | ||
Cow::Borrowed(b) => SimpleString::Borrowed(b), | ||
Cow::Owned(o) => SimpleString::Owned(o), | ||
} | ||
} | ||
} | ||
|
||
impl From<&String> for SimpleString { | ||
fn from(s: &String) -> Self { | ||
SimpleString::Owned(s.clone()) | ||
} | ||
} | ||
|
||
impl Deref for SimpleString { | ||
type Target = str; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
self.as_str() | ||
} | ||
} | ||
|
||
impl From<SimpleString> for String { | ||
fn from(s: SimpleString) -> Self { | ||
s.into_owned() | ||
} | ||
} | ||
|
||
impl std::fmt::Display for SimpleString { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.as_str()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.