Merge branch 'main' into chat-to-list

This commit is contained in:
Xithrius 2023-03-08 19:59:38 -08:00 committed by GitHub
commit fa8bd6bd69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 59 additions and 28 deletions

View File

@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: cargo login ${CRATES_IO_TOKEN}
env:

10
Cargo.lock generated
View File

@ -120,9 +120,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.1.4"
version = "4.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
checksum = "ec0b0588d44d4d63a87dbd75c136c166bbfd9a86a31cb89e09906521c7d3f5e3"
dependencies = [
"bitflags",
"clap_derive",
@ -250,9 +250,9 @@ dependencies = [
[[package]]
name = "crossterm"
version = "0.26.0"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77f67c7faacd4db07a939f55d66a983a5355358a1f17d32cc9a8d01d1266b9ce"
checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13"
dependencies = [
"bitflags",
"crossterm_winapi",
@ -1650,7 +1650,7 @@ dependencies = [
"chrono",
"clap",
"color-eyre",
"crossterm 0.26.0",
"crossterm 0.26.1",
"dialoguer",
"fern",
"futures",

View File

@ -13,10 +13,10 @@ keywords = ["tui", "twitch"]
categories = ["command-line-utilities"]
[dependencies]
crossterm = "0.26.0"
crossterm = "0.26.1"
tui = { version = "0.19.0", default-features = false, features = [ "crossterm" ] }
tokio = { version = "1.25.0", features = [ "rt", "macros", "rt-multi-thread" ] }
clap = { version = "4.1.4", features = [ "derive", "cargo" ] }
tokio = { version = "1.24.1", features = [ "rt", "macros", "rt-multi-thread" ] }
clap = { version = "4.1.6", features = [ "derive", "cargo" ] }
serde = { version = "1.0.152", features = [ "derive" ] }
serde_json = "1.0.93"
unicode-width = "0.1.10"

View File

@ -39,22 +39,10 @@ pub fn reset_terminal() {
pub fn init_terminal(frontend_config: &FrontendConfig) -> Terminal<CrosstermBackend<Stdout>> {
enable_raw_mode().unwrap();
let blink = |a: SetCursorStyle, b: SetCursorStyle| -> SetCursorStyle {
if frontend_config.blinking_cursor {
a
} else {
b
}
};
let cursor_type = match frontend_config.cursor_shape {
CursorType::User => SetCursorStyle::DefaultUserShape,
CursorType::Line => blink(SetCursorStyle::BlinkingBar, SetCursorStyle::SteadyBar),
CursorType::Block => blink(SetCursorStyle::BlinkingBlock, SetCursorStyle::SteadyBlock),
CursorType::UnderScore => blink(
SetCursorStyle::BlinkingUnderScore,
SetCursorStyle::SteadyUnderScore,
),
let cursor_style = match frontend_config.cursor_shape {
CursorType::Line => SetCursorStyle::BlinkingBar,
CursorType::Block => SetCursorStyle::BlinkingBlock,
CursorType::UnderScore => SetCursorStyle::BlinkingUnderScore,
};
let mut stdout = stdout();
@ -63,7 +51,7 @@ pub fn init_terminal(frontend_config: &FrontendConfig) -> Terminal<CrosstermBack
stdout,
EnterAlternateScreen,
EnableMouseCapture,
cursor_type,
cursor_style,
)
.unwrap();

View File

@ -15,7 +15,7 @@ use crate::{
},
},
twitch::TwitchAction,
ui::draw_ui,
ui::{draw_ui, error::draw_error_ui},
};
pub async fn ui_driver(
@ -56,7 +56,22 @@ pub async fn ui_driver(
}
terminal
.draw(|frame| draw_ui(frame, &mut app, &config))
.draw(|frame| {
let size = frame.size();
if size.height < 10 || size.width < 60 {
draw_error_ui(
frame,
&[
"Window to small!",
"Must allow for at least 60x10.",
"Restart and resize.",
],
);
} else {
draw_ui(frame, &mut app, &config);
}
})
.unwrap();
if matches!(

27
src/ui/error.rs Normal file
View File

@ -0,0 +1,27 @@
use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout},
style::{Color, Style},
terminal::Frame,
text::{Span, Spans},
widgets::{Block, Borders, Paragraph},
};
pub fn draw_error_ui<T: Backend>(frame: &mut Frame<T>, messages: &[&str]) {
let v_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Min(1)])
.split(frame.size());
let paragraph = Paragraph::new(
messages
.iter()
.map(|&s| Spans::from(vec![Span::raw(s)]))
.collect::<Vec<Spans>>(),
)
.block(Block::default().borders(Borders::NONE))
.style(Style::default().fg(Color::White))
.alignment(Alignment::Center);
frame.render_widget(paragraph, v_chunks[0]);
}

View File

@ -24,6 +24,7 @@ use crate::{
};
pub mod components;
pub mod error;
pub mod statics;
#[derive(Debug, Clone)]