Skip to content

Commit 3db4fa0

Browse files
committed
fix: variables may not set in interactive mode
1 parent 6d3a010 commit 3db4fa0

File tree

5 files changed

+34
-51
lines changed

5 files changed

+34
-51
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ jobs:
110110
- name: Run tests
111111
run: cargo test --verbose
112112
vhs:
113-
runs-on: macos-latest
113+
runs-on: windows-latest
114114
steps:
115115
- uses: actions/checkout@v3
116116
- uses: charmbracelet/vhs-action@v1

.github/workflows/vhs.yml

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

assets/envfetch.tape

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,30 @@ Output envfetch.gif
6565

6666
Require envfetch
6767

68-
Set TypingSpeed 400ms
68+
Set TypingSpeed 150ms
6969
Set FontSize 32
7070
Set Width 2400
7171
Set Height 1200
7272

7373
# Basic set
7474
Type "envfetch set MY_VAR_TEST 'Hello for everyone!' -- echo hello" Sleep 500ms Enter
75-
Sleep 500ms
75+
#Sleep 500ms
7676
Type "envfetch get MY_VAR_TEST" Sleep 500ms Enter
77-
Sleep 500ms
77+
#Sleep 500ms
7878
# Global set
7979
Type "envfetch set MY_VAR_TEST 'Hello for everyone!' --global" Sleep 500ms Enter
80-
Sleep 500ms
80+
#Sleep 500ms
8181
# Get with wrong name
8282
Type "envfetch get MY_VAR_TESTT" Sleep 500ms Enter
83-
Sleep 500ms
83+
#Sleep 500ms
8484
# Get with normal name
8585
Type "envfetch get MY_VAR_TEST" Sleep 500ms Enter
86-
Sleep 500ms
86+
#Sleep 500ms
8787
# Add globally
8888
Type "envfetch add MY_VAR_TEST ! --global" Sleep 500ms Enter
89-
Sleep 500ms
89+
#Sleep 500ms
9090
# Remove globally
9191
Type "envfetch delete MY_VAR_TEST --global" Sleep 500ms Enter
92-
Sleep 500ms
92+
#Sleep 500ms
9393

9494
Sleep 5s

envfetch.gif

1.8 MB
Loading

src/interactive/controller.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::interactive::state::{AppState, InputFocus, Mode};
2+
use crate::variables;
23
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
34
use std::io;
45
use std::time::Duration;
@@ -84,11 +85,16 @@ pub fn handle_add_mode(state: &mut AppState, key: KeyEvent) {
8485
match key.code {
8586
KeyCode::Enter => {
8687
if !state.input_key.trim().is_empty() {
87-
state.entries.push((
88-
state.input_key.trim().to_string(),
89-
state.input_value.trim().to_string(),
90-
));
91-
state.show_message("Variable added", Duration::from_secs(2));
88+
match variables::set_variable(state.input_key.trim(), state.input_value.trim(), true) {
89+
Err(err) => state.show_message(&format!("Failed to add variable: {}", err), Duration::from_secs(2)),
90+
Ok(_) => {
91+
state.entries.push((
92+
state.input_key.trim().to_string(),
93+
state.input_value.trim().to_string(),
94+
));
95+
state.show_message("Variable added", Duration::from_secs(2));
96+
}
97+
}
9298
state.mode = Mode::List;
9399
} else {
94100
state.show_message("Key cannot be empty", Duration::from_secs(2));
@@ -158,8 +164,13 @@ pub fn handle_edit_mode(state: &mut AppState, key: KeyEvent) {
158164
KeyCode::Enter => {
159165
if let Mode::Edit(ref key_name) = state.mode {
160166
if let Some(entry) = state.entries.iter_mut().find(|(k, _)| k == key_name) {
161-
entry.1 = state.input_value.trim().to_string();
162-
state.show_message("Variable updated", Duration::from_secs(2));
167+
match variables::set_variable(key_name, state.input_value.trim(), true) {
168+
Err(err) => state.show_message(&format!("Failed to update variable: {}", err), Duration::from_secs(2)),
169+
Ok(_) => {
170+
entry.1 = state.input_value.trim().to_string();
171+
state.show_message("Variable updated", Duration::from_secs(2))
172+
}
173+
}
163174
}
164175
state.mode = Mode::List;
165176
}
@@ -193,8 +204,13 @@ pub fn handle_delete_mode(state: &mut AppState, key: KeyEvent) {
193204
match key.code {
194205
KeyCode::Char('y') => {
195206
if let Mode::Delete(ref key_name) = state.mode {
196-
state.entries.retain(|(k, _)| k != key_name);
197-
state.show_message("Variable deleted", Duration::from_secs(2));
207+
match variables::delete_variable(key_name.to_owned(), true) {
208+
Err(err) => state.show_message(&format!("Failed to delete variable: {}", err), Duration::from_secs(2)),
209+
Ok(_) => {
210+
state.entries.retain(|(k, _)| k != key_name);
211+
state.show_message("Variable deleted", Duration::from_secs(2))
212+
}
213+
}
198214
}
199215
state.mode = Mode::List;
200216
}

0 commit comments

Comments
 (0)