Skip to content

Commit 804a6c2

Browse files
author
cht
committed
make pop window can edit
1 parent 931067e commit 804a6c2

2 files changed

Lines changed: 70 additions & 54 deletions

File tree

src/main.rs

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum InputMode {
3838
struct App {
3939
/// Current value of the input box
4040
input: String,
41+
v2ray_input: String,
4142
/// Current input mode
4243
input_mode: InputMode,
4344
/// History of recorded messages
@@ -87,6 +88,7 @@ impl Default for App {
8788
fn default() -> App {
8889
App {
8990
input: String::new(),
91+
v2ray_input: String::new(),
9092
input_mode: InputMode::Normal,
9193
messages: Vec::new(),
9294
state: ListState::default(),
@@ -176,37 +178,7 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
176178
for alist in &list[0] {
177179
let information = spider::Information::new(alist.to_string());
178180
app.informations.push(information.clone());
179-
storge.push_str(
180-
format!(
181-
"{{
182-
\"func\":{},
183-
\"url\":\"{}\",
184-
\"add\":{},
185-
\"aid\":{},
186-
\"host\":{},
187-
\"id\":{},
188-
\"net\":{},
189-
\"path\":{},
190-
\"port\":{},
191-
\"ps\":{},
192-
\"tls\":{},
193-
\"type\":{}
194-
}},\n",
195-
information.clone().func,
196-
information.clone().urls,
197-
information.clone().add,
198-
information.clone().aid,
199-
information.clone().host,
200-
information.clone().id,
201-
information.clone().net,
202-
information.clone().path,
203-
information.clone().port,
204-
information.clone().ps,
205-
information.clone().tls,
206-
information.clone().typpe
207-
)
208-
.as_str(),
209-
);
181+
storge.push_str(information.get_the_json_node().as_str());
210182
}
211183
}
212184
storge.pop();
@@ -248,23 +220,26 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
248220
app.input_mode = InputMode::Normal;
249221
}
250222
}
251-
InputMode::Popup => {
252-
match key.code {
253-
KeyCode::Char('q') => {
254-
app.input_mode = InputMode::Normal;
255-
app.show_popup = false;
256-
},
257-
KeyCode::Char('e') => {
258-
app.input_mode = InputMode::PopupEdit;
259-
},
260-
_ => {}
223+
InputMode::Popup => match key.code {
224+
KeyCode::Char('q') => {
225+
app.input_mode = InputMode::Normal;
226+
app.show_popup = false;
261227
}
262-
}
228+
KeyCode::Char('e') => {
229+
app.input_mode = InputMode::PopupEdit;
230+
}
231+
_ => {}
232+
},
263233
InputMode::PopupEdit => {
264234
match key.code {
265-
KeyCode::Char('q') => app.input_mode = InputMode::Popup,
235+
KeyCode::Esc => app.input_mode = InputMode::Popup,
266236
// here todo
267-
KeyCode::Char('e') => todo!(),
237+
KeyCode::Char(c) => {
238+
app.v2ray_input.push(c);
239+
}
240+
KeyCode::Backspace => {
241+
app.v2ray_input.pop();
242+
}
268243
_ => {}
269244
}
270245
}
@@ -333,14 +308,14 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
333308
})
334309
.block(Block::default().borders(Borders::ALL).title("Input"));
335310
f.render_widget(input, chunks[1]);
336-
if let InputMode::Editing = app.input_mode {
337-
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
338-
f.set_cursor(
339-
// Put cursor past the end of the input text
340-
chunks[1].x + app.input.width() as u16 + 1,
341-
// Move one line down, from the border to the input line
342-
chunks[1].y + 1,
343-
)
311+
if let InputMode::Editing = app.input_mode {
312+
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
313+
f.set_cursor(
314+
// Put cursor past the end of the input text
315+
chunks[1].x + app.input.width() as u16 + 1,
316+
// Move one line down, from the border to the input line
317+
chunks[1].y + 1,
318+
)
344319
//InputMode::Normal | InputMode::Select | InputMode::Popup =>
345320
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
346321
}
@@ -392,16 +367,27 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
392367

393368
if app.show_popup {
394369
//let block = Block::default().title("About port").borders(Borders::ALL);
395-
let inputpop = Paragraph::new(app.input.as_ref())
370+
let inputpop = Paragraph::new(app.v2ray_input.as_ref())
396371
.style(match app.input_mode {
397372
InputMode::PopupEdit => Style::default().fg(Color::Yellow),
398373
_ => Style::default(),
399374
})
400-
.block(Block::default().borders(Borders::ALL).title("Input"));
375+
.block(Block::default().borders(Borders::ALL).title("Settings"));
401376
//f.render_widget(input, chunks[1]);
402377
let area = centered_rect(60, 20, f.size());
403378
f.render_widget(Clear, area); //this clears out the background
404379
f.render_widget(inputpop, area);
380+
if let InputMode::PopupEdit = app.input_mode {
381+
// Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering
382+
f.set_cursor(
383+
// Put cursor past the end of the input text
384+
area.x + app.v2ray_input.width() as u16 + 1,
385+
// Move one line down, from the border to the input line
386+
area.y + 1,
387+
)
388+
//InputMode::Normal | InputMode::Select | InputMode::Popup =>
389+
// Hide the cursor. `Frame` does this by default, so we don't need to do anything here
390+
}
405391
}
406392
}
407393
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {

src/spider.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ impl Information {
9898
}
9999
temp
100100
}
101+
pub fn get_the_json_node(&self) -> String {
102+
format!(
103+
"{{
104+
\"func\":{},
105+
\"url\":\"{}\",
106+
\"add\":{},
107+
\"aid\":{},
108+
\"host\":{},
109+
\"id\":{},
110+
\"net\":{},
111+
\"path\":{},
112+
\"port\":{},
113+
\"ps\":{},
114+
\"tls\":{},
115+
\"type\":{}
116+
}},\n",
117+
self.func,
118+
self.urls,
119+
self.add,
120+
self.aid,
121+
self.host,
122+
self.id,
123+
self.net,
124+
self.path,
125+
self.port,
126+
self.ps,
127+
self.tls,
128+
self.typpe
129+
)
130+
}
101131
pub fn new(url: String) -> Self {
102132
let aurl: Vec<char> = url.chars().collect();
103133
let url_type = {

0 commit comments

Comments
 (0)