Skip to content

Commit 526cc86

Browse files
committed
Update dependencies and refactor UI code
1 parent bc5393f commit 526cc86

6 files changed

Lines changed: 63 additions & 71 deletions

File tree

.github/dependabot.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222

2323
jobs:
2424
build:
25-
runs-on: ubuntu-20.04
25+
runs-on: ubuntu-24.04
2626

2727
steps:
2828
- name: Checkout code
@@ -45,7 +45,7 @@ jobs:
4545
deploy:
4646
if: ${{ github.event.inputs.deploy == 'true' }}
4747
needs: [build]
48-
runs-on: ubuntu-20.04
48+
runs-on: ubuntu-24.04
4949

5050
steps:
5151
- name: Checkout code

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "gcoma"
3-
version = "2.1.0"
4-
edition = "2021"
3+
version = "2.2.0"
4+
edition = "2024"
55
readme = "README.md"
66
license = "Apache-2.0"
77

88
[dependencies]
9-
clap = { version = "4.4.12", features = ["derive"] }
10-
crossterm = "0.27.0"
11-
ratatui = "0.26.1"
12-
serde = { version = "1.0.193", features = ["derive"] }
13-
serde_json = "1.0.1"
14-
tui-textarea = "0.4.0"
9+
clap = { version = "4.5.45", features = ["derive"] }
10+
crossterm = "0.29.0"
11+
ratatui = "0.29.0"
12+
serde = { version = "1.0.219", features = ["derive"] }
13+
serde_json = "1.0.143"
14+
tui-textarea = "0.7.0"

src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ fn main() -> io::Result<()> {
2727
let matches = args::get_args();
2828
let cfg_path = matches.get_one::<String>("user_config");
2929

30-
if cfg_path.is_some() {
31-
let user_config = load_cfg_from_file(cfg_path.unwrap().as_str());
30+
if let Some(path) = cfg_path {
31+
let user_config = load_cfg_from_file(path.as_str());
3232

3333
let list_flag = matches.get_one::<bool>("list").unwrap_or(&false).to_owned();
3434
let connect_idx = matches.get_one::<String>("connect");
35-
let rm_sg = matches.get_one::<String>("remove");
35+
let remove_sg = matches.get_one::<String>("remove");
3636

3737
if list_flag {
3838
let mut i = 0;
@@ -45,8 +45,8 @@ fn main() -> io::Result<()> {
4545
i += 1;
4646
}
4747
}
48-
} else if connect_idx.is_some() {
49-
let mut idx: usize = connect_idx.unwrap().parse().unwrap();
48+
} else if let Some(idx) = connect_idx {
49+
let mut idx: usize = idx.parse().unwrap();
5050

5151
for sg in user_config?.session_groups.iter() {
5252
for s in sg.sessions.iter() {
@@ -57,9 +57,9 @@ fn main() -> io::Result<()> {
5757
idx -= 1;
5858
}
5959
}
60-
} else if rm_sg.is_some() {
60+
} else if let Some(rm_sg) = remove_sg {
6161
let mut ucfg = user_config.unwrap_or(Config::new());
62-
let sg_name = rm_sg.unwrap().to_owned();
62+
let sg_name = rm_sg.to_owned();
6363

6464
ucfg.session_groups.retain(|sg| sg.name != sg_name);
6565

src/session_core/connection_type.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use serde::{Deserialize, Serialize};
22
use std::convert::TryFrom;
3+
use std::fmt;
34

45
#[allow(clippy::upper_case_acronyms)]
56
#[derive(Serialize, Deserialize, PartialEq, Clone)]
@@ -8,12 +9,13 @@ pub enum ConnectionType {
89
SSH,
910
}
1011

11-
impl ToString for ConnectionType {
12-
fn to_string(&self) -> String {
13-
match self {
14-
ConnectionType::Telnet => "telnet".to_string(),
15-
ConnectionType::SSH => "ssh".to_string(),
16-
}
12+
impl fmt::Display for ConnectionType {
13+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14+
let s = match self {
15+
ConnectionType::Telnet => "telnet",
16+
ConnectionType::SSH => "ssh",
17+
};
18+
write!(f, "{}", s)
1719
}
1820
}
1921

src/ui/view.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crossterm::{
1+
use ratatui::crossterm::{
22
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode},
33
execute,
4-
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
4+
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
55
};
66
use ratatui::{prelude::*, widgets::*};
77

8-
use std::io::{self, stdout, Stdout};
8+
use std::io::{self, Stdout, stdout};
99
use std::vec;
1010
use tui_textarea::{Input, Key};
1111

@@ -76,10 +76,7 @@ fn remove_selected(state: &mut ViewState) {
7676
}
7777

7878
fn find_selected(state: &mut ViewState) -> Option<Session> {
79-
let mut selected_idx = match state.table_state.selected() {
80-
Some(i) => i,
81-
None => return None,
82-
};
79+
let mut selected_idx = state.table_state.selected()?;
8380

8481
for session_group in state.config.session_groups.iter() {
8582
if selected_idx == 0 {
@@ -101,26 +98,26 @@ fn find_selected(state: &mut ViewState) -> Option<Session> {
10198
}
10299

103100
fn handle_normal_mode_events(state: &mut ViewState, cfg_path: &str) -> io::Result<bool> {
104-
if let Event::Key(key) = event::read()? {
105-
if key.kind == event::KeyEventKind::Press {
106-
match key.code {
107-
KeyCode::Char('q') | KeyCode::Esc => {
108-
// Quit
109-
return Ok(true);
110-
}
111-
KeyCode::Char('a') => state.popup_state.show(),
112-
KeyCode::Char('r') => {
113-
remove_selected(state);
114-
state.config.save(cfg_path);
115-
}
116-
KeyCode::Char('R') => {
117-
state.config = load_cfg_from_file(cfg_path).unwrap_or(Config::new());
118-
}
119-
KeyCode::Enter => state.connected = true,
120-
KeyCode::Down | KeyCode::Char('j') => state.next(),
121-
KeyCode::Up | KeyCode::Char('k') => state.previous(),
122-
_ => {}
101+
if let Event::Key(key) = event::read()?
102+
&& key.kind == event::KeyEventKind::Press
103+
{
104+
match key.code {
105+
KeyCode::Char('q') | KeyCode::Esc => {
106+
// Quit
107+
return Ok(true);
108+
}
109+
KeyCode::Char('a') => state.popup_state.show(),
110+
KeyCode::Char('r') => {
111+
remove_selected(state);
112+
state.config.save(cfg_path);
113+
}
114+
KeyCode::Char('R') => {
115+
state.config = load_cfg_from_file(cfg_path).unwrap_or(Config::new());
123116
}
117+
KeyCode::Enter => state.connected = true,
118+
KeyCode::Down | KeyCode::Char('j') => state.next(),
119+
KeyCode::Up | KeyCode::Char('k') => state.previous(),
120+
_ => {}
124121
}
125122
}
126123

@@ -246,21 +243,24 @@ fn table_ui(state: &mut ViewState, frame: &mut Frame, area: &Rect) {
246243
)
247244
.header(header)
248245
.block(Block::default().borders(Borders::ALL).title("Sessions"))
249-
.highlight_style(Style::default().add_modifier(Modifier::REVERSED))
246+
.row_highlight_style(Style::default().add_modifier(Modifier::REVERSED))
250247
.highlight_symbol(">> ");
251248

252249
frame.render_stateful_widget(t, *area, &mut state.table_state);
253250
}
254251

255252
fn popup_ui(state: &mut ViewState, frame: &mut Frame) {
256253
let create_block = |title, border, modifier, color| {
257-
Block::default().borders(border).gray().title(Span::styled(
258-
title,
259-
Style::default().add_modifier(modifier).fg(color),
260-
))
254+
block::Block::default()
255+
.borders(border)
256+
.gray()
257+
.title(Span::styled(
258+
title,
259+
Style::default().add_modifier(modifier).fg(color),
260+
))
261261
};
262262

263-
let area = create_centered_rect(50, 50, frame.size());
263+
let area = create_centered_rect(50, 50, frame.area());
264264
let chunks = Layout::new(
265265
Direction::Vertical,
266266
[Constraint::Percentage(100), Constraint::Percentage(100)],
@@ -297,8 +297,8 @@ fn popup_ui(state: &mut ViewState, frame: &mut Frame) {
297297
));
298298
textarea.set_placeholder_text(placeholder);
299299
frame.render_widget(
300-
textarea.widget(),
301-
chunks[0].inner(&Margin {
300+
&*textarea,
301+
chunks[0].inner(Margin {
302302
vertical: 1,
303303
horizontal: 2,
304304
}),
@@ -312,7 +312,7 @@ fn popup_ui(state: &mut ViewState, frame: &mut Frame) {
312312
let paragraph = Paragraph::new(line).bold();
313313
frame.render_widget(
314314
paragraph,
315-
chunks[0].inner(&Margin {
315+
chunks[0].inner(Margin {
316316
vertical: 1,
317317
horizontal: 2,
318318
}),
@@ -326,7 +326,7 @@ fn ui(state: &mut ViewState, frame: &mut Frame) {
326326
Direction::Vertical,
327327
[Constraint::Length(1), Constraint::Min(0)],
328328
)
329-
.split(frame.size());
329+
.split(frame.area());
330330

331331
// Title
332332
frame.render_widget(
@@ -380,10 +380,10 @@ fn connect_selected_ui(
380380
terminal.draw(|frame| {
381381
frame.render_widget(
382382
Block::default().title(text).borders(Borders::TOP),
383-
frame.size(),
383+
frame.area(),
384384
)
385385
})?;
386-
terminal.set_cursor(0, 1)?;
386+
terminal.set_cursor_position(Position { x: 0, y: 1 })?;
387387
terminal.show_cursor()?;
388388

389389
disable_raw_mode()?;

0 commit comments

Comments
 (0)