Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved showing tips to a feature #566

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/linutil.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
run: cargo install cross

- name: Build x86_64 binary
run: cargo build --target-dir=build --release --verbose --target=x86_64-unknown-linux-musl
run: cargo build --target-dir=build --release --verbose --target=x86_64-unknown-linux-musl --all-features

- name: Build aarch64 binary
run: cross build --target-dir=build --release --verbose --target=aarch64-unknown-linux-musl
run: cross build --target-dir=build --release --verbose --target=aarch64-unknown-linux-musl --all-features

- name: Move binaries to build directory
run: |
Expand Down
6 changes: 5 additions & 1 deletion tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ include = [
]
build = "build.rs"

[features]
default = ["tips"]
tips = []

[dependencies]
clap = { version = "4.5.16", features = ["derive"] }
crossterm = "0.28.1"
Expand All @@ -32,4 +36,4 @@ chrono = "0.4.33"

[[bin]]
name = "linutil"
path = "src/main.rs"
path = "src/main.rs"
11 changes: 10 additions & 1 deletion tui/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use ego_tree::NodeId;
use linutil_core::{Command, ListNode, Tab};
#[cfg(feature = "tips")]
use rand::Rng;
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout},
Expand Down Expand Up @@ -40,6 +41,7 @@ pub struct AppState {
multi_select: bool,
selected_commands: Vec<Command>,
drawable: bool,
#[cfg(feature = "tips")]
tip: &'static str,
}

Expand Down Expand Up @@ -71,6 +73,7 @@ impl AppState {
multi_select: false,
selected_commands: Vec::new(),
drawable: false,
#[cfg(feature = "tips")]
tip: get_random_line(include_str!("../cool_tips.txt").lines().collect()),
};
state.update_items();
Expand Down Expand Up @@ -246,14 +249,19 @@ impl AppState {
self.multi_select.then(|| "[Multi-Select]").unwrap_or("")
);

#[cfg(feature = "tips")]
let bottom_title = Line::from(self.tip.bold().blue()).right_aligned();
#[cfg(not(feature = "tips"))]
let bottom_title = "";

// Create the list widget with items
let list = List::new(items)
.highlight_style(style)
.block(
Block::default()
.borders(Borders::ALL)
.title(title)
.title_bottom(Line::from(self.tip.bold().blue()).right_aligned()),
.title_bottom(bottom_title),
)
.scroll_padding(1);
frame.render_stateful_widget(list, chunks[1], &mut self.selection);
Expand Down Expand Up @@ -534,6 +542,7 @@ impl AppState {
}
}

#[cfg(feature = "tips")]
fn get_random_line(lines: Vec<&str>) -> &str {
if lines.is_empty() {
return "";
Expand Down