Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90974d064e |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1123,7 +1123,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ostiary"
|
name = "ostiary"
|
||||||
version = "1.0.10"
|
version = "1.0.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ostiary"
|
name = "ostiary"
|
||||||
version = "1.0.10"
|
version = "1.0.9"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
61
README.md
61
README.md
@@ -9,7 +9,7 @@
|
|||||||
### Быстрая установка (Linux / macOS)
|
### Быстрая установка (Linux / macOS)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://vainend.com/ostiary | bash
|
curl -fsSL https://git.vainend.com/admin/ostiary/raw/branch/master/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
Скрипт определяет ОС и архитектуру, скачивает последний стабильный релиз и устанавливает бинарник в `~/.local/bin/ostiary`. Если этого пути нет в `$PATH` — автоматически добавляет строку в `~/.bashrc` (или `~/.bash_profile` / `~/.profile`). Не требует `sudo`.
|
Скрипт определяет ОС и архитектуру, скачивает последний стабильный релиз и устанавливает бинарник в `~/.local/bin/ostiary`. Если этого пути нет в `$PATH` — автоматически добавляет строку в `~/.bashrc` (или `~/.bash_profile` / `~/.profile`). Не требует `sudo`.
|
||||||
@@ -38,7 +38,7 @@ source ~/.bashrc
|
|||||||
### Удаление
|
### Удаление
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -fsSL https://vainend.com/ostiary-remove | bash
|
curl -fsSL https://git.vainend.com/admin/ostiary/raw/branch/master/uninstall.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
Или вручную:
|
Или вручную:
|
||||||
@@ -75,14 +75,13 @@ INSTALL_DIR=~/.local/bin bash install.sh
|
|||||||
|
|
||||||
### Popup запущенного скрипта
|
### Popup запущенного скрипта
|
||||||
|
|
||||||
| Клавиша | Контекст | Действие |
|
| Клавиша | Действие |
|
||||||
|---|---|---|
|
|---|---|
|
||||||
| `↑` / `↓` или `k` / `j` | Лог / селектор / форма | Прокрутка лога или навигация между элементами |
|
| `↑` / `↓` или `k` / `j` | Прокрутка лога / навигация по селектору |
|
||||||
| `PgUp` / `PgDn` | Лог | Прокрутка на 10 строк |
|
| `PgUp` / `PgDn` | Прокрутка лога на 10 строк |
|
||||||
| `Space` | Форма | Переключить чекбокс / выбрать радиокнопку |
|
| `Y` / `N` или `l` / `h` | Ответ на подтверждение (без Enter) |
|
||||||
| `Y` / `N` или `l` / `h` | Подтверждение | Ответ без Enter |
|
| `Enter` или `l` | Выбрать пункт селектора / подтвердить |
|
||||||
| `Enter` или `l` | Любой ввод | Отправить / выбрать / применить форму |
|
| `Esc` или `h` | Прервать скрипт и закрыть popup |
|
||||||
| `Esc` или `h` | — | Прервать скрипт и закрыть popup |
|
|
||||||
|
|
||||||
> Vim-motions (`j`/`k`/`l`/`h`) отключаются автоматически во время текстового ввода — символы идут в поле ввода как обычно.
|
> Vim-motions (`j`/`k`/`l`/`h`) отключаются автоматически во время текстового ввода — символы идут в поле ввода как обычно.
|
||||||
|
|
||||||
@@ -432,48 +431,6 @@ notify '{"type":"progress","percent":100,"message":"Готово!"}'
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Форма с чекбоксами и радиокнопками (`form`)
|
|
||||||
|
|
||||||
Отображает список полей с возможностью навигации и переключения. Возвращает строку с ID всех включённых/выбранных полей через пробел.
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"type": "form",
|
|
||||||
"prompt": "Параметры поиска:",
|
|
||||||
"fields": [
|
|
||||||
{"id": "verbose", "label": "Подробный вывод", "field_type": "checkbox", "default": false},
|
|
||||||
{"id": "php", "label": "PHP файлы (*.php)", "field_type": "radio", "group": "ftype", "default": true},
|
|
||||||
{"id": "js", "label": "JS файлы (*.js)", "field_type": "radio", "group": "ftype", "default": false}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
| Поле | Описание |
|
|
||||||
|---|---|
|
|
||||||
| `id` | Идентификатор, возвращается если поле включено |
|
|
||||||
| `label` | Отображаемый текст |
|
|
||||||
| `field_type` | `"checkbox"` или `"radio"` |
|
|
||||||
| `default` | Начальное состояние |
|
|
||||||
| `group` | Группа радиокнопок — одновременно активна только одна в группе |
|
|
||||||
|
|
||||||
**Ответ:** строка с ID активных полей через пробел: `"verbose php"`
|
|
||||||
|
|
||||||
**Клавиши внутри формы:** `↑`/`↓`/`j`/`k` — навигация, `Space` — переключить, `Enter`/`l` — применить, `Esc` — отмена.
|
|
||||||
|
|
||||||
**Важно:** весь JSON должен быть на **одной строке** — протокол читает строки, не блоки.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
result=$(ask '{"type":"form","prompt":"Параметры:","fields":[{"id":"verbose","label":"Подробный вывод","field_type":"checkbox","default":false},{"id":"php","label":"PHP файлы","field_type":"radio","group":"t","default":true},{"id":"js","label":"JS файлы","field_type":"radio","group":"t","default":false}]}')
|
|
||||||
|
|
||||||
is_on() { [[ " $result " == *" $1 "* ]]; }
|
|
||||||
|
|
||||||
is_on "verbose" && FLAGS+=("-v")
|
|
||||||
is_on "php" && INCLUDE="--include=*.php"
|
|
||||||
is_on "js" && INCLUDE="--include=*.js"
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Запуск внешнего приложения (`exec`)
|
### Запуск внешнего приложения (`exec`)
|
||||||
|
|
||||||
Временно **передаёт терминал** внешней программе (mysql, vim, htop и др.). Клиент скрывает TUI, программа работает на полном экране, после завершения TUI восстанавливается. Возвращает код завершения.
|
Временно **передаёт терминал** внешней программе (mysql, vim, htop и др.). Клиент скрывает TUI, программа работает на полном экране, после завершения TUI восстанавливается. Возвращает код завершения.
|
||||||
|
|||||||
142
src/app.rs
142
src/app.rs
@@ -61,10 +61,6 @@ pub enum Popup {
|
|||||||
input_buffer: String,
|
input_buffer: String,
|
||||||
/// Cursor position for Menu-type commands.
|
/// Cursor position for Menu-type commands.
|
||||||
menu_selected_index: usize,
|
menu_selected_index: usize,
|
||||||
/// Cursor position for Form-type commands.
|
|
||||||
form_cursor: usize,
|
|
||||||
/// Checked/selected state for each Form field (parallel to fields vec).
|
|
||||||
form_values: Vec<bool>,
|
|
||||||
/// Index of the first visible line in log_buffer (0 = top of output).
|
/// Index of the first visible line in log_buffer (0 = top of output).
|
||||||
log_scroll_pos: usize,
|
log_scroll_pos: usize,
|
||||||
/// When true, keep position pinned to the bottom as new output arrives.
|
/// When true, keep position pinned to the bottom as new output arrives.
|
||||||
@@ -201,20 +197,11 @@ impl App {
|
|||||||
if let Some(Popup::ExecutingStructured {
|
if let Some(Popup::ExecutingStructured {
|
||||||
current_command,
|
current_command,
|
||||||
menu_selected_index,
|
menu_selected_index,
|
||||||
form_cursor,
|
|
||||||
form_values,
|
|
||||||
..
|
..
|
||||||
}) = &mut self.popup
|
}) = &mut self.popup
|
||||||
{
|
{
|
||||||
match &cmd {
|
if matches!(cmd, executor::StructuredCommand::Menu { .. }) {
|
||||||
executor::StructuredCommand::Menu { .. } => {
|
*menu_selected_index = 0;
|
||||||
*menu_selected_index = 0;
|
|
||||||
}
|
|
||||||
executor::StructuredCommand::Form { fields, .. } => {
|
|
||||||
*form_cursor = 0;
|
|
||||||
*form_values = fields.iter().map(|f| f.default).collect();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
*current_command = Some(cmd);
|
*current_command = Some(cmd);
|
||||||
}
|
}
|
||||||
@@ -298,8 +285,6 @@ impl App {
|
|||||||
input_buffer,
|
input_buffer,
|
||||||
current_command,
|
current_command,
|
||||||
menu_selected_index,
|
menu_selected_index,
|
||||||
form_cursor,
|
|
||||||
form_values,
|
|
||||||
log_scroll_pos,
|
log_scroll_pos,
|
||||||
log_follow_bottom,
|
log_follow_bottom,
|
||||||
log_buffer,
|
log_buffer,
|
||||||
@@ -313,10 +298,6 @@ impl App {
|
|||||||
current_command,
|
current_command,
|
||||||
Some(executor::StructuredCommand::Confirm { .. })
|
Some(executor::StructuredCommand::Confirm { .. })
|
||||||
);
|
);
|
||||||
let is_form = matches!(
|
|
||||||
current_command,
|
|
||||||
Some(executor::StructuredCommand::Form { .. })
|
|
||||||
);
|
|
||||||
let has_command = current_command.is_some();
|
let has_command = current_command.is_some();
|
||||||
// Vim motions are disabled only when free text input is active.
|
// Vim motions are disabled only when free text input is active.
|
||||||
let is_text_input = matches!(
|
let is_text_input = matches!(
|
||||||
@@ -338,53 +319,6 @@ impl App {
|
|||||||
*log_scroll_pos + 1 >= log_buffer.len();
|
*log_scroll_pos + 1 >= log_buffer.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Form: navigation and toggle ──────────────────
|
|
||||||
KeyCode::Up if is_form => {
|
|
||||||
if *form_cursor > 0 { *form_cursor -= 1; }
|
|
||||||
}
|
|
||||||
KeyCode::Down if is_form => {
|
|
||||||
let len = if let Some(
|
|
||||||
executor::StructuredCommand::Form { fields, .. }
|
|
||||||
) = current_command { fields.len() } else { 0 };
|
|
||||||
if *form_cursor + 1 < len { *form_cursor += 1; }
|
|
||||||
}
|
|
||||||
KeyCode::Char(' ') if is_form => {
|
|
||||||
let cursor = *form_cursor;
|
|
||||||
// Collect toggle info before mutating form_values
|
|
||||||
let toggle = if let Some(
|
|
||||||
executor::StructuredCommand::Form { fields, .. }
|
|
||||||
) = current_command {
|
|
||||||
fields.get(cursor).map(|f| {
|
|
||||||
let group_indices: Vec<usize> = fields.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|(_, ff)| {
|
|
||||||
ff.group.is_some()
|
|
||||||
&& ff.group == f.group
|
|
||||||
})
|
|
||||||
.map(|(i, _)| i)
|
|
||||||
.collect();
|
|
||||||
(f.field_type.clone(), group_indices)
|
|
||||||
})
|
|
||||||
} else { None };
|
|
||||||
|
|
||||||
if let Some((ftype, group_indices)) = toggle {
|
|
||||||
match ftype {
|
|
||||||
executor::FormFieldType::Checkbox => {
|
|
||||||
if let Some(v) = form_values.get_mut(cursor) {
|
|
||||||
*v = !*v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
executor::FormFieldType::Radio => {
|
|
||||||
for i in group_indices {
|
|
||||||
if let Some(v) = form_values.get_mut(i) {
|
|
||||||
*v = i == cursor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Arrow keys ────────────────────────────────────
|
// ── Arrow keys ────────────────────────────────────
|
||||||
KeyCode::Up if is_menu => {
|
KeyCode::Up if is_menu => {
|
||||||
if *menu_selected_index > 0 {
|
if *menu_selected_index > 0 {
|
||||||
@@ -425,41 +359,23 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Text input ────────────────────────────────────
|
// ── Text input ────────────────────────────────────
|
||||||
// Excluded: vim motions (j/k/l/h) and form mode.
|
// Vim motion keys (j/k/l/h) are excluded here so they
|
||||||
|
// fall through to the vim-motion arms below.
|
||||||
KeyCode::Char(c)
|
KeyCode::Char(c)
|
||||||
if !is_menu
|
if !is_menu
|
||||||
&& !is_confirm
|
&& !is_confirm
|
||||||
&& !is_form
|
|
||||||
&& (is_text_input
|
&& (is_text_input
|
||||||
|| !matches!(c, 'j' | 'k' | 'l' | 'h')) =>
|
|| !matches!(c, 'j' | 'k' | 'l' | 'h')) =>
|
||||||
{
|
{
|
||||||
input_buffer.push(c);
|
input_buffer.push(c);
|
||||||
}
|
}
|
||||||
KeyCode::Backspace if !is_menu && !is_form => {
|
KeyCode::Backspace if !is_menu => {
|
||||||
input_buffer.pop();
|
input_buffer.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Enter: commit response ────────────────────────
|
// ── Enter: commit response ────────────────────────
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
// Form submit: collect checked IDs
|
if let Some(cmd) = current_command.take() {
|
||||||
if is_form {
|
|
||||||
if let Some(executor::StructuredCommand::Form {
|
|
||||||
fields, ..
|
|
||||||
}) = current_command.take() {
|
|
||||||
let response = fields.iter().enumerate()
|
|
||||||
.filter_map(|(i, f)| {
|
|
||||||
form_values.get(i)
|
|
||||||
.copied()
|
|
||||||
.filter(|&v| v)
|
|
||||||
.map(|_| f.id.as_str())
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(" ");
|
|
||||||
let _ = reply_tx.send(response);
|
|
||||||
form_values.clear();
|
|
||||||
*form_cursor = 0;
|
|
||||||
}
|
|
||||||
} else if let Some(cmd) = current_command.take() {
|
|
||||||
let response = match &cmd {
|
let response = match &cmd {
|
||||||
executor::StructuredCommand::Input { .. } => {
|
executor::StructuredCommand::Input { .. } => {
|
||||||
input_buffer.clone()
|
input_buffer.clone()
|
||||||
@@ -477,6 +393,7 @@ impl App {
|
|||||||
.get(*menu_selected_index)
|
.get(*menu_selected_index)
|
||||||
.map(|opt| opt.id.clone())
|
.map(|opt| opt.id.clone())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
|
// Message / Progress: send empty ack.
|
||||||
_ => String::new(),
|
_ => String::new(),
|
||||||
};
|
};
|
||||||
let _ = reply_tx.send(response);
|
let _ = reply_tx.send(response);
|
||||||
@@ -501,9 +418,9 @@ impl App {
|
|||||||
// ── Vim motions (off during text input) ───────────
|
// ── Vim motions (off during text input) ───────────
|
||||||
KeyCode::Char('k') if !is_text_input => {
|
KeyCode::Char('k') if !is_text_input => {
|
||||||
if is_menu {
|
if is_menu {
|
||||||
if *menu_selected_index > 0 { *menu_selected_index -= 1; }
|
if *menu_selected_index > 0 {
|
||||||
} else if is_form {
|
*menu_selected_index -= 1;
|
||||||
if *form_cursor > 0 { *form_cursor -= 1; }
|
}
|
||||||
} else if !has_command {
|
} else if !has_command {
|
||||||
*log_scroll_pos = log_scroll_pos.saturating_sub(1);
|
*log_scroll_pos = log_scroll_pos.saturating_sub(1);
|
||||||
*log_follow_bottom = false;
|
*log_follow_bottom = false;
|
||||||
@@ -513,16 +430,12 @@ impl App {
|
|||||||
if is_menu {
|
if is_menu {
|
||||||
if let Some(executor::StructuredCommand::Menu {
|
if let Some(executor::StructuredCommand::Menu {
|
||||||
options, ..
|
options, ..
|
||||||
}) = current_command {
|
}) = current_command
|
||||||
|
{
|
||||||
if *menu_selected_index + 1 < options.len() {
|
if *menu_selected_index + 1 < options.len() {
|
||||||
*menu_selected_index += 1;
|
*menu_selected_index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if is_form {
|
|
||||||
let len = if let Some(
|
|
||||||
executor::StructuredCommand::Form { fields, .. }
|
|
||||||
) = current_command { fields.len() } else { 0 };
|
|
||||||
if *form_cursor + 1 < len { *form_cursor += 1; }
|
|
||||||
} else if !has_command {
|
} else if !has_command {
|
||||||
*log_scroll_pos = log_scroll_pos.saturating_add(1);
|
*log_scroll_pos = log_scroll_pos.saturating_add(1);
|
||||||
*log_follow_bottom =
|
*log_follow_bottom =
|
||||||
@@ -530,31 +443,18 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('l') if !is_text_input => {
|
KeyCode::Char('l') if !is_text_input => {
|
||||||
// Form submit
|
// Forward / confirm — same logic as Enter.
|
||||||
if is_form {
|
if let Some(cmd) = current_command.take() {
|
||||||
if let Some(executor::StructuredCommand::Form {
|
|
||||||
fields, ..
|
|
||||||
}) = current_command.take() {
|
|
||||||
let response = fields.iter().enumerate()
|
|
||||||
.filter_map(|(i, f)| {
|
|
||||||
form_values.get(i).copied()
|
|
||||||
.filter(|&v| v).map(|_| f.id.as_str())
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>().join(" ");
|
|
||||||
let _ = reply_tx.send(response);
|
|
||||||
form_values.clear();
|
|
||||||
*form_cursor = 0;
|
|
||||||
}
|
|
||||||
} else if let Some(cmd) = current_command.take() {
|
|
||||||
let response = match &cmd {
|
let response = match &cmd {
|
||||||
executor::StructuredCommand::Confirm { .. } => {
|
executor::StructuredCommand::Confirm { .. } => {
|
||||||
"y".to_string()
|
"y".to_string()
|
||||||
}
|
}
|
||||||
executor::StructuredCommand::Menu { options, .. } => {
|
executor::StructuredCommand::Menu {
|
||||||
options.get(*menu_selected_index)
|
options, ..
|
||||||
.map(|o| o.id.clone())
|
} => options
|
||||||
.unwrap_or_default()
|
.get(*menu_selected_index)
|
||||||
}
|
.map(|o| o.id.clone())
|
||||||
|
.unwrap_or_default(),
|
||||||
_ => String::new(),
|
_ => String::new(),
|
||||||
};
|
};
|
||||||
let _ = reply_tx.send(response);
|
let _ = reply_tx.send(response);
|
||||||
@@ -791,8 +691,6 @@ impl App {
|
|||||||
current_command: None,
|
current_command: None,
|
||||||
input_buffer: String::new(),
|
input_buffer: String::new(),
|
||||||
menu_selected_index: 0,
|
menu_selected_index: 0,
|
||||||
form_cursor: 0,
|
|
||||||
form_values: Vec::new(),
|
|
||||||
log_scroll_pos: 0,
|
log_scroll_pos: 0,
|
||||||
log_follow_bottom: false,
|
log_follow_bottom: false,
|
||||||
finished: None,
|
finished: None,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
pub mod structured;
|
pub mod structured;
|
||||||
pub use structured::{StructuredCommand, MessageLevel, FormField, FormFieldType};
|
pub use structured::{StructuredCommand, MessageLevel};
|
||||||
|
|
||||||
// Здесь могут быть функции для download, http и т.д.
|
// Здесь могут быть функции для download, http и т.д.
|
||||||
|
|||||||
@@ -31,34 +31,15 @@ pub enum StructuredCommand {
|
|||||||
percent: u8,
|
percent: u8,
|
||||||
message: Option<String>,
|
message: Option<String>,
|
||||||
},
|
},
|
||||||
/// A list of checkboxes and radio buttons.
|
|
||||||
/// Response: space-separated IDs of all checked/selected fields.
|
|
||||||
Form {
|
|
||||||
prompt: String,
|
|
||||||
fields: Vec<FormField>,
|
|
||||||
},
|
|
||||||
/// Run an interactive program that needs the real terminal.
|
/// Run an interactive program that needs the real terminal.
|
||||||
|
/// The client suspends ratatui, inherits stdin/stdout/stderr, waits for
|
||||||
|
/// the process to exit, then restores the TUI.
|
||||||
|
/// The script receives the exit code as the response.
|
||||||
Exec {
|
Exec {
|
||||||
shell: String,
|
shell: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub enum FormFieldType {
|
|
||||||
Checkbox,
|
|
||||||
Radio,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct FormField {
|
|
||||||
pub id: String,
|
|
||||||
pub label: String,
|
|
||||||
pub field_type: FormFieldType,
|
|
||||||
pub default: bool,
|
|
||||||
/// Radio buttons with the same group are mutually exclusive.
|
|
||||||
pub group: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MenuOption {
|
pub struct MenuOption {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
@@ -222,25 +203,6 @@ fn parse_command(json_str: &str, cmd_tx: UnboundedSender<StructuredCommand>) ->
|
|||||||
let message = v["message"].as_str().map(String::from);
|
let message = v["message"].as_str().map(String::from);
|
||||||
StructuredCommand::Progress { percent, message }
|
StructuredCommand::Progress { percent, message }
|
||||||
}
|
}
|
||||||
"form" => {
|
|
||||||
let prompt = v["prompt"].as_str().unwrap_or("").to_string();
|
|
||||||
let fields = v["fields"].as_array()
|
|
||||||
.map(|arr| {
|
|
||||||
arr.iter().filter_map(|f| {
|
|
||||||
let id = f["id"].as_str()?.to_string();
|
|
||||||
let label = f["label"].as_str()?.to_string();
|
|
||||||
let field_type = match f["field_type"].as_str().unwrap_or("checkbox") {
|
|
||||||
"radio" => FormFieldType::Radio,
|
|
||||||
_ => FormFieldType::Checkbox,
|
|
||||||
};
|
|
||||||
let default = f["default"].as_bool().unwrap_or(false);
|
|
||||||
let group = f["group"].as_str().map(String::from);
|
|
||||||
Some(FormField { id, label, field_type, default, group })
|
|
||||||
}).collect()
|
|
||||||
})
|
|
||||||
.unwrap_or_default();
|
|
||||||
StructuredCommand::Form { prompt, fields }
|
|
||||||
}
|
|
||||||
"exec" => {
|
"exec" => {
|
||||||
let shell = v["shell"].as_str().unwrap_or("").to_string();
|
let shell = v["shell"].as_str().unwrap_or("").to_string();
|
||||||
StructuredCommand::Exec { shell }
|
StructuredCommand::Exec { shell }
|
||||||
|
|||||||
55
src/ui.rs
55
src/ui.rs
@@ -132,8 +132,6 @@ fn render_popup(f: &mut Frame, popup: &mut Popup) {
|
|||||||
current_command,
|
current_command,
|
||||||
input_buffer,
|
input_buffer,
|
||||||
menu_selected_index,
|
menu_selected_index,
|
||||||
form_cursor,
|
|
||||||
form_values,
|
|
||||||
log_scroll_pos,
|
log_scroll_pos,
|
||||||
log_follow_bottom,
|
log_follow_bottom,
|
||||||
finished,
|
finished,
|
||||||
@@ -142,9 +140,6 @@ fn render_popup(f: &mut Frame, popup: &mut Popup) {
|
|||||||
Some(executor::StructuredCommand::Menu { options, .. }) => {
|
Some(executor::StructuredCommand::Menu { options, .. }) => {
|
||||||
(options.len() as u16 + 2).min(14)
|
(options.len() as u16 + 2).min(14)
|
||||||
}
|
}
|
||||||
Some(executor::StructuredCommand::Form { fields, .. }) => {
|
|
||||||
(fields.len() as u16 + 2).min(16)
|
|
||||||
}
|
|
||||||
Some(_) => 5,
|
Some(_) => 5,
|
||||||
None => 0,
|
None => 0,
|
||||||
};
|
};
|
||||||
@@ -234,12 +229,7 @@ fn render_popup(f: &mut Frame, popup: &mut Popup) {
|
|||||||
// ── Interactive command area ─────────────────────────────────────
|
// ── Interactive command area ─────────────────────────────────────
|
||||||
if cmd_height > 0 {
|
if cmd_height > 0 {
|
||||||
if let Some(cmd) = current_command {
|
if let Some(cmd) = current_command {
|
||||||
render_command(
|
render_command(f, cmd, input_buffer, *menu_selected_index, chunks[1]);
|
||||||
f, cmd, input_buffer,
|
|
||||||
*menu_selected_index,
|
|
||||||
*form_cursor, form_values,
|
|
||||||
chunks[1],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,8 +364,6 @@ fn render_command(
|
|||||||
cmd: &executor::StructuredCommand,
|
cmd: &executor::StructuredCommand,
|
||||||
input_buffer: &str,
|
input_buffer: &str,
|
||||||
menu_selected_index: usize,
|
menu_selected_index: usize,
|
||||||
form_cursor: usize,
|
|
||||||
form_values: &[bool],
|
|
||||||
area: Rect,
|
area: Rect,
|
||||||
) {
|
) {
|
||||||
match cmd {
|
match cmd {
|
||||||
@@ -504,47 +492,6 @@ fn render_command(
|
|||||||
f.render_widget(paragraph, area);
|
f.render_widget(paragraph, area);
|
||||||
}
|
}
|
||||||
|
|
||||||
executor::StructuredCommand::Form { prompt, fields } => {
|
|
||||||
let items: Vec<ListItem> = fields.iter().enumerate().map(|(i, field)| {
|
|
||||||
let checked = form_values.get(i).copied().unwrap_or(false);
|
|
||||||
let icon = match field.field_type {
|
|
||||||
executor::FormFieldType::Checkbox => {
|
|
||||||
if checked { "[✓]" } else { "[ ]" }
|
|
||||||
}
|
|
||||||
executor::FormFieldType::Radio => {
|
|
||||||
if checked { "(●)" } else { "( )" }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let is_cursor = i == form_cursor;
|
|
||||||
let prefix = if is_cursor { "▶ " } else { " " };
|
|
||||||
let style = if is_cursor {
|
|
||||||
Style::default().bg(Color::Blue).add_modifier(Modifier::BOLD)
|
|
||||||
} else {
|
|
||||||
Style::default()
|
|
||||||
};
|
|
||||||
ListItem::new(Line::from(vec![
|
|
||||||
Span::raw(format!("{}{} {}", prefix, icon, field.label)),
|
|
||||||
])).style(style)
|
|
||||||
}).collect();
|
|
||||||
|
|
||||||
let mut state = ListState::default();
|
|
||||||
state.select(Some(form_cursor));
|
|
||||||
|
|
||||||
let list = List::new(items).block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.title(format!(" {} ", prompt))
|
|
||||||
.title_bottom(
|
|
||||||
Line::from(Span::styled(
|
|
||||||
" Space — переключить Enter/l — применить Esc — отмена ",
|
|
||||||
Style::default().fg(Color::DarkGray),
|
|
||||||
)).alignment(Alignment::Right),
|
|
||||||
)
|
|
||||||
.border_style(Style::default().fg(Color::Cyan)),
|
|
||||||
);
|
|
||||||
f.render_stateful_widget(list, area, &mut state);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec is handled by the main loop before rendering; this arm is
|
// Exec is handled by the main loop before rendering; this arm is
|
||||||
// never reached in practice but satisfies the exhaustiveness check.
|
// never reached in practice but satisfies the exhaustiveness check.
|
||||||
executor::StructuredCommand::Exec { shell } => {
|
executor::StructuredCommand::Exec { shell } => {
|
||||||
|
|||||||
48
uninstall.sh
48
uninstall.sh
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
BINARY="ostiary"
|
BINARY="ostiary"
|
||||||
INSTALL_DIR="$HOME/.local/bin"
|
INSTALL_DIR="$HOME/.local/bin"
|
||||||
@@ -11,54 +12,49 @@ info() { echo -e "${CYAN}[ostiary]${NC} $*"; }
|
|||||||
ok() { echo -e "${GREEN}[ostiary]${NC} $*"; }
|
ok() { echo -e "${GREEN}[ostiary]${NC} $*"; }
|
||||||
warn() { echo -e "${YELLOW}[ostiary]${NC} $*"; }
|
warn() { echo -e "${YELLOW}[ostiary]${NC} $*"; }
|
||||||
|
|
||||||
# Read from /dev/tty so the script works when piped through bash
|
|
||||||
# (e.g. curl ... | bash), where stdin is the pipe, not the terminal.
|
|
||||||
ask() {
|
|
||||||
local answer
|
|
||||||
read -rp "$1 [y/N] " answer </dev/tty
|
|
||||||
[[ "$answer" =~ ^[Yy]$ ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
# ── Remove binary ────────────────────────────────────────────────────────────
|
# ── Remove binary ────────────────────────────────────────────────────────────
|
||||||
BINARY_PATH="$INSTALL_DIR/$BINARY"
|
BINARY_PATH="$INSTALL_DIR/$BINARY"
|
||||||
|
|
||||||
if [ -f "$BINARY_PATH" ]; then
|
if [ -f "$BINARY_PATH" ]; then
|
||||||
info "Найден бинарник: $BINARY_PATH"
|
info "Found binary: $BINARY_PATH"
|
||||||
if ask " Удалить?"; then
|
read -rp " Remove it? [y/N] " answer
|
||||||
|
if [[ "$answer" =~ ^[Yy]$ ]]; then
|
||||||
rm "$BINARY_PATH"
|
rm "$BINARY_PATH"
|
||||||
ok "Бинарник удалён"
|
ok "Binary removed"
|
||||||
else
|
|
||||||
ok "Бинарник оставлен"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
warn "Бинарник не найден в $BINARY_PATH"
|
warn "Binary not found at $BINARY_PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Remove config ────────────────────────────────────────────────────────────
|
# ── Remove config ────────────────────────────────────────────────────────────
|
||||||
echo ""
|
|
||||||
if [ -d "$CONFIG_DIR" ]; then
|
if [ -d "$CONFIG_DIR" ]; then
|
||||||
info "Найден конфиг: $CONFIG_DIR"
|
echo ""
|
||||||
if ask " Удалить конфиг и настройки?"; then
|
info "Config directory: $CONFIG_DIR"
|
||||||
|
read -rp " Remove config and saved settings? [y/N] " answer
|
||||||
|
if [[ "$answer" =~ ^[Yy]$ ]]; then
|
||||||
rm -rf "$CONFIG_DIR"
|
rm -rf "$CONFIG_DIR"
|
||||||
ok "Конфиг удалён"
|
ok "Config removed"
|
||||||
else
|
else
|
||||||
ok "Конфиг оставлен: $CONFIG_DIR"
|
ok "Config kept at $CONFIG_DIR"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ── Remove PATH entry from shell profile ─────────────────────────────────────
|
# ── Remove PATH entry from shell profile ─────────────────────────────────────
|
||||||
for PROFILE in "$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.profile"; do
|
for PROFILE in "$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.profile"; do
|
||||||
if [ -f "$PROFILE" ] && grep -qF "# Added by ostiary installer" "$PROFILE"; then
|
if [ -f "$PROFILE" ] && grep -qF ".local/bin" "$PROFILE"; then
|
||||||
echo ""
|
echo ""
|
||||||
info "Найдена запись PATH в $PROFILE"
|
info "Found PATH entry in $PROFILE"
|
||||||
if ask " Удалить строку PATH, добавленную установщиком?"; then
|
read -rp " Remove the PATH line added by ostiary installer? [y/N] " answer
|
||||||
sed -i '/# Added by ostiary installer/d' "$PROFILE"
|
if [[ "$answer" =~ ^[Yy]$ ]]; then
|
||||||
sed -i '/\.local\/bin.*PATH/d' "$PROFILE"
|
# Remove the comment and the export line added by install.sh
|
||||||
ok "Запись PATH удалена из $PROFILE"
|
sed -i.bak '/# Added by ostiary installer/d' "$PROFILE"
|
||||||
|
sed -i.bak '/\.local\/bin.*PATH/d' "$PROFILE"
|
||||||
|
rm -f "${PROFILE}.bak"
|
||||||
|
ok "PATH entry removed from $PROFILE"
|
||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
ok "Готово"
|
ok "Done"
|
||||||
|
|||||||
Reference in New Issue
Block a user