mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-13 00:20:08 +01:00
refactor: HintAlignment -> ui/hint_alignment.rs
This commit is contained in:
parent
6ba1bd9454
commit
7c7799ffbd
3 changed files with 29 additions and 27 deletions
26
src/ui/hint_alignment.rs
Normal file
26
src/ui/hint_alignment.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
use clap::Clap;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use crate::error::ParseError;
|
||||||
|
|
||||||
|
/// Describes if, during rendering, a hint should aligned to the leading edge of
|
||||||
|
/// the matched text, or to its trailing edge.
|
||||||
|
#[derive(Debug, Clap)]
|
||||||
|
pub enum HintAlignment {
|
||||||
|
Leading,
|
||||||
|
Trailing,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for HintAlignment {
|
||||||
|
type Err = ParseError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<HintAlignment, ParseError> {
|
||||||
|
match s {
|
||||||
|
"leading" => Ok(HintAlignment::Leading),
|
||||||
|
"trailing" => Ok(HintAlignment::Trailing),
|
||||||
|
_ => Err(ParseError::ExpectedString(String::from(
|
||||||
|
"leading or trailing",
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,11 +18,12 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
pub mod colors;
|
pub mod colors;
|
||||||
|
pub mod hint_alignment;
|
||||||
pub mod hint_style;
|
pub mod hint_style;
|
||||||
mod selection;
|
mod selection;
|
||||||
mod vc;
|
mod vc;
|
||||||
|
|
||||||
|
pub use hint_alignment::HintAlignment;
|
||||||
pub use hint_style::HintStyle;
|
pub use hint_style::HintStyle;
|
||||||
pub use selection::Selection;
|
pub use selection::Selection;
|
||||||
pub use vc::HintAlignment;
|
|
||||||
pub use vc::ViewController;
|
pub use vc::ViewController;
|
||||||
|
|
|
||||||
27
src/ui/vc.rs
27
src/ui/vc.rs
|
|
@ -1,16 +1,13 @@
|
||||||
use std::char;
|
use std::char;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use clap::Clap;
|
|
||||||
use sequence_trie::SequenceTrie;
|
use sequence_trie::SequenceTrie;
|
||||||
use termion::{self, color, cursor, event, style};
|
use termion::{self, color, cursor, event, style};
|
||||||
|
|
||||||
use super::colors::UiColors;
|
use super::colors::UiColors;
|
||||||
use super::HintStyle;
|
|
||||||
use super::Selection;
|
use super::Selection;
|
||||||
use crate::error::ParseError;
|
use super::{HintAlignment, HintStyle};
|
||||||
use crate::{output_destination::OutputDestination, textbuf};
|
use crate::{output_destination::OutputDestination, textbuf};
|
||||||
|
|
||||||
pub struct ViewController<'a> {
|
pub struct ViewController<'a> {
|
||||||
|
|
@ -608,28 +605,6 @@ fn get_line_offsets(lines: &[&str], term_width: u16) -> Vec<usize> {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describes if, during rendering, a hint should aligned to the leading edge of
|
|
||||||
/// the matched text, or to its trailing edge.
|
|
||||||
#[derive(Debug, Clap)]
|
|
||||||
pub enum HintAlignment {
|
|
||||||
Leading,
|
|
||||||
Trailing,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for HintAlignment {
|
|
||||||
type Err = ParseError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<HintAlignment, ParseError> {
|
|
||||||
match s {
|
|
||||||
"leading" => Ok(HintAlignment::Leading),
|
|
||||||
"trailing" => Ok(HintAlignment::Trailing),
|
|
||||||
_ => Err(ParseError::ExpectedString(String::from(
|
|
||||||
"leading or trailing",
|
|
||||||
))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returned value after the `Ui` has finished listening to events.
|
/// Returned value after the `Ui` has finished listening to events.
|
||||||
enum Event {
|
enum Event {
|
||||||
/// Exit with no selected matches,
|
/// Exit with no selected matches,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue