Configuracoes: caminho do arquivo de config + toggle da variavel de ambiente

- tb_environ_config_path: caminho padrao ($XDG_CONFIG_HOME/tinyblocks/
  settings.csv ou $HOME/.config/tinyblocks/settings.csv).
- tb_environ_env_path: le TINYBLOCKS_SETTINGS.
- tb_environ_export_csv_meta: escreve uma linha de metadados
  "# arquivo_config,<caminho>" antes da tabela; export_csv agora tambem
  cria as pastas do caminho (mkdir -p).

- Editor: o CSV de settings passa a ser salvo no caminho do arquivo de
  configuracao (mostrado no campo) e inclui esse caminho no proprio CSV.
- Nova linha de opcoes com o toggle "Detectar caminho de
  TINYBLOCKS_SETTINGS" (checkbox): ligado usa a variavel de ambiente,
  desligado usa o caminho padrao; mostra o valor atual (ou "nao definida").

- Testes: test-environ cobre config_path/env_path/export_csv_meta e a
  criacao de pastas; harness passa a ligar o toggle com TINYBLOCKS_SETTINGS
  e confere a linha de metadados no CSV.
This commit is contained in:
mguinhos committed 2026-10-20 20:44:16 -03:00
1 parent 7fc3a18234
commit a14c7f9937
7 files changed
+139 -1088

No files matched your search

+47 -5
View File
@@ -438,6 +438,7 @@ typedef struct {
bool settings_open;
int settings_sel; /* linha selecionada (-1 = nenhuma) */
bool settings_path_focus; /* campo de caminho do CSV em foco */
bool settings_use_env; /* caminho vindo de TINYBLOCKS_SETTINGS */
bool settings_value_edit; /* editando o valor da linha sel. */
bool settings_new_key; /* digitando o nome de uma nova chave */
char settings_path[256];
@@ -3110,12 +3111,25 @@ static void libman_scroll_by(Ed* ed, float dy) {
* Configuracoes (settings) - store da tinyblocks-environ, salvo/exportado em CSV
* === */
#define ST_HEAD_H 64
#define ST_TOOL_Y ST_HEAD_H
#define ST_OPT_Y ST_HEAD_H
#define ST_OPT_H 40
#define ST_TOOL_Y (ST_HEAD_H + ST_OPT_H)
#define ST_TOOL_H 64
#define ST_MARGIN 40
#define ST_ROW_H 40
#define ST_LIST_Y (ST_TOOL_Y + ST_TOOL_H + 6)
#define ST_BTN_H 40
#define ST_ENV_LABEL "Detectar caminho de TINYBLOCKS_SETTINGS"
/* Recalcula o caminho do config: da variavel de ambiente (se o toggle
* estiver ligado e a variavel existir) ou o caminho padrao do sistema. */
static void settings_sync_path(Ed* ed) {
if (ed->settings_use_env) {
const char* e = tb_environ_env_path();
if (e[0]) { snprintf(ed->settings_path, sizeof(ed->settings_path), "%s", e); return; }
}
tb_environ_config_path(ed->settings_path, sizeof(ed->settings_path));
}
static void settings_show(Ed* ed) {
ed->settings_open = true;
@@ -3125,7 +3139,7 @@ static void settings_show(Ed* ed) {
ed->settings_new_key = false;
ed->settings_scroll = 0;
ed->settings_hover = -1;
if (!ed->settings_path[0]) strcpy(ed->settings_path, "tinyblocks-settings.csv");
settings_sync_path(ed);
ed->libman_open = false;
ed->path_input_active = false;
ed->ctx_menu_open = false;
@@ -3159,7 +3173,8 @@ static void st_button(TinyBlocks_RenderableBlock* rb, float x, float y, float w,
}
static void settings_export(Ed* ed, const char* path) {
bool ok = tb_environ_export_csv(path);
if (!path || !path[0]) path = ed->settings_path;
bool ok = tb_environ_export_csv_meta(path, "arquivo_config", path);
if (ok) snprintf(ed->hot_status, sizeof(ed->hot_status),
"Configuracoes salvas (CSV): %.200s", path);
else snprintf(ed->hot_status, sizeof(ed->hot_status),
@@ -3190,6 +3205,24 @@ static void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
{ const char* t = "Configurações";
rb_text_c(rb, (WIN_W - tw(t, 20)) * 0.5f, by, t, COL_WHITE, 20); }
/* Opcoes: toggle de deteccao do caminho pela variavel de ambiente */
rb_fill_rect(rb, 0, ST_OPT_Y, WIN_W, ST_OPT_H, COL_FLY);
{
float cb = ST_OPT_Y + (ST_OPT_H - 20) * 0.5f;
rb_fill_rrect(rb, ST_MARGIN, cb, 20, 20, 4,
ed->settings_use_env ? COL_MENU : COL_WHITE);
rb_stroke_rect(rb, ST_MARGIN, cb, 20, 20, 2.f, COL_MENU);
if (ed->settings_use_env) {
rb_line(rb, ST_MARGIN + 4, cb + 10, ST_MARGIN + 8, cb + 15, 2.5f, COL_WHITE);
rb_line(rb, ST_MARGIN + 8, cb + 15, ST_MARGIN + 16, cb + 5, 2.5f, COL_WHITE);
}
rb_text_c(rb, ST_MARGIN + 30, ST_OPT_Y + ST_OPT_H*0.5f, ST_ENV_LABEL, COL_TEXT, FS_UI);
const char* e = tb_environ_env_path();
const char* hint = e[0] ? e : "TINYBLOCKS_SETTINGS nao definida";
rb_text_c(rb, WIN_W - ST_MARGIN - tw(hint, FS_SM), ST_OPT_Y + ST_OPT_H*0.5f,
hint, e[0] ? COL_TEXT_DIM : COL_ERR_MENU, FS_SM);
}
/* Barra de ferramentas */
rb_fill_rect(rb, 0, ST_TOOL_Y, WIN_W, ST_TOOL_H, COL_PANEL);
{
@@ -3258,6 +3291,14 @@ static void settings_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
static void settings_click(Ed* ed, float mx, float my) {
if (my < ST_HEAD_H) { if (mx < 170) settings_close(ed); return; }
if (my < ST_OPT_Y + ST_OPT_H) {
if (in_rect(mx, my, ST_MARGIN, ST_OPT_Y, 540, ST_OPT_H)) {
ed->settings_use_env = !ed->settings_use_env;
settings_sync_path(ed);
}
return;
}
if (my < ST_TOOL_Y + ST_TOOL_H) {
float px, py, pw, ph; settings_path_rect(ed, &px, &py, &pw, &ph);
if (in_rect(mx, my, px, py, pw, ph)) {
@@ -3268,7 +3309,7 @@ static void settings_click(Ed* ed, float mx, float my) {
float x, y, w, h; settings_btn_rect(ed, i, &x, &y, &w, &h);
if (!in_rect(mx, my, x, y, w, h)) continue;
ed->settings_path_focus = false;
if (i == 0) settings_export(ed, "tinyblocks-settings.csv");
if (i == 0) settings_export(ed, ed->settings_path);
else if (i == 1) settings_export(ed, ed->settings_path);
else { ed->settings_new_key = true; ed->settings_key[0] = 0;
ed->settings_value_edit = false; ed->settings_sel = -1;
@@ -3998,7 +4039,8 @@ static bool editor_instance_init(TinyBlocks_Block* self, TinyBlocks* rt) {
ed->ctx_menu_bi = -1;
ed->path_mode = PM_NONE;
ed->settings_sel = -1;
strcpy(ed->settings_path, "tinyblocks-settings.csv");
ed->settings_use_env = false;
settings_sync_path(ed);
ed->tab_n = 1;
ed->cur_tab = 0;