Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/tui/components/ColorMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
getAvailableColorsForUI
} from '../../utils/colors';
import { GRADIENT_PRESET_NAMES } from '../../utils/gradient';
import { shouldInsertInput } from '../../utils/input-guards';
import {
getPlainInput,
shouldInsertInput
} from '../../utils/input-guards';
import { getWidget } from '../../utils/widgets';

import { ConfirmDialog } from './ConfirmDialog';
Expand Down Expand Up @@ -68,6 +71,7 @@ export const ColorMenu: React.FC<ColorMenuProps> = ({ widgets, lineIndex, settin
// Handle keyboard input
const hasNoItems = colorableWidgets.length === 0;
useInput((input, key) => {
const shortcut = getPlainInput(input, key);
// If no items, any key goes back
if (hasNoItems) {
onBack();
Expand Down Expand Up @@ -234,19 +238,19 @@ export const ColorMenu: React.FC<ColorMenuProps> = ({ widgets, lineIndex, settin
if (highlightedItemId === 'back') {
onBack();
}
} else if (input === 'h' || input === 'H') {
} else if (shortcut === 'h' || shortcut === 'H') {
// Enter hex input mode (only in truecolor mode)
if (highlightedItemId && highlightedItemId !== 'back' && settings.colorLevel === 3) {
setHexInputMode(true);
setHexInput('');
}
} else if (input === 'a' || input === 'A') {
} else if (shortcut === 'a' || shortcut === 'A') {
// Enter ansi256 input mode (only in 256 color mode)
if (highlightedItemId && highlightedItemId !== 'back' && settings.colorLevel === 2) {
setAnsi256InputMode(true);
setAnsi256Input('');
}
} else if (input === 'g' || input === 'G') {
} else if (shortcut === 'g' || shortcut === 'G') {
// Enter gradient selection mode (foreground only, needs a real color palette)
if (highlightedItemId && highlightedItemId !== 'back' && !editingBackground && settings.colorLevel >= 2) {
setGradientMode(true);
Expand All @@ -255,7 +259,7 @@ export const ColorMenu: React.FC<ColorMenuProps> = ({ widgets, lineIndex, settin
setGradientStartHex('');
setGradientHexInput('');
}
} else if ((input === 's' || input === 'S') && !key.ctrl) {
} else if (shortcut === 's' || shortcut === 'S') {
// Toggle show separators (only if not in powerline mode and no default separator)
if (!settings.powerline.enabled && !settings.defaultSeparator) {
setShowSeparators(!showSeparators);
Expand All @@ -267,11 +271,11 @@ export const ColorMenu: React.FC<ColorMenuProps> = ({ widgets, lineIndex, settin
setHighlightedItemId(colorableWidgets.find(widget => widget.type !== 'separator')?.id ?? null);
}
}
} else if (input === 'f' || input === 'F') {
} else if (shortcut === 'f' || shortcut === 'F') {
if (colorableWidgets.length > 0) {
setEditingBackground(!editingBackground);
}
} else if (input === 'b' || input === 'B') {
} else if (shortcut === 'b' || shortcut === 'B') {
if (highlightedItemId && highlightedItemId !== 'back') {
// Toggle bold for the highlighted item
const selectedWidget = colorableWidgets.find(widget => widget.id === highlightedItemId);
Expand All @@ -280,7 +284,7 @@ export const ColorMenu: React.FC<ColorMenuProps> = ({ widgets, lineIndex, settin
onUpdate(newItems);
}
}
} else if (input === 'd' || input === 'D') {
} else if (shortcut === 'd' || shortcut === 'D') {
if (highlightedItemId && highlightedItemId !== 'back') {
// Cycle dim for the highlighted item: off -> whole -> parens -> off
const selectedWidget = colorableWidgets.find(widget => widget.id === highlightedItemId);
Expand All @@ -289,7 +293,7 @@ export const ColorMenu: React.FC<ColorMenuProps> = ({ widgets, lineIndex, settin
onUpdate(newItems);
}
}
} else if (input === 'r' || input === 'R') {
} else if (shortcut === 'r' || shortcut === 'R') {
if (highlightedItemId && highlightedItemId !== 'back') {
// Reset all styling (color, background, and bold) for the highlighted item
const selectedWidget = colorableWidgets.find(widget => widget.id === highlightedItemId);
Expand All @@ -298,7 +302,7 @@ export const ColorMenu: React.FC<ColorMenuProps> = ({ widgets, lineIndex, settin
onUpdate(newItems);
}
}
} else if (input === 'c' || input === 'C') {
} else if (shortcut === 'c' || shortcut === 'C') {
// Show clear all confirmation
setShowClearConfirm(true);
} else if (key.leftArrow || key.rightArrow) {
Expand Down
30 changes: 17 additions & 13 deletions src/tui/components/GlobalOverridesMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
getColorDisplayName
} from '../../utils/colors';
import { GRADIENT_PRESET_NAMES } from '../../utils/gradient';
import { shouldInsertInput } from '../../utils/input-guards';
import {
getPlainInput,
shouldInsertInput
} from '../../utils/input-guards';
import { getNextNumberStyle } from '../../utils/number-format';

import { ConfirmDialog } from './ConfirmDialog';
Expand Down Expand Up @@ -90,6 +93,7 @@ export const GlobalOverridesMenu: React.FC<GlobalOverridesMenuProps> = ({ settin
const currentFgIndex = fgColors.indexOf(settings.overrideForegroundColor ?? 'none');

useInput((input, key) => {
const shortcut = getPlainInput(input, key);
if (editingPadding) {
if (key.return) {
const updatedSettings = {
Expand Down Expand Up @@ -213,19 +217,19 @@ export const GlobalOverridesMenu: React.FC<GlobalOverridesMenuProps> = ({ settin
} else {
if (key.escape) {
onBack();
} else if (input === 'p' || input === 'P') {
} else if (shortcut === 'p' || shortcut === 'P') {
setEditingPadding(true);
} else if ((input === 's' || input === 'S') && !isPowerlineEnabled && !key.ctrl) {
} else if ((shortcut === 's' || shortcut === 'S') && !isPowerlineEnabled) {
setEditingSeparator(true);
} else if ((input === 'i' || input === 'I') && !isPowerlineEnabled) {
} else if ((shortcut === 'i' || shortcut === 'I') && !isPowerlineEnabled) {
const newInheritColors = !inheritColors;
setInheritColors(newInheritColors);
const updatedSettings = {
...settings,
inheritSeparatorColors: newInheritColors
};
onUpdate(updatedSettings);
} else if ((input === 'b' || input === 'B') && !isPowerlineEnabled) {
} else if ((shortcut === 'b' || shortcut === 'B') && !isPowerlineEnabled) {
// Cycle through background colors
const nextIndex = (currentBgIndex + 1) % bgColors.length;
const nextBgColor = bgColors[nextIndex];
Expand All @@ -234,14 +238,14 @@ export const GlobalOverridesMenu: React.FC<GlobalOverridesMenuProps> = ({ settin
overrideBackgroundColor: nextBgColor === 'none' ? undefined : nextBgColor
};
onUpdate(updatedSettings);
} else if ((input === 'c' || input === 'C') && !isPowerlineEnabled) {
} else if ((shortcut === 'c' || shortcut === 'C') && !isPowerlineEnabled) {
// Clear override background color
const updatedSettings = {
...settings,
overrideBackgroundColor: undefined
};
onUpdate(updatedSettings);
} else if (input === 'o' || input === 'O') {
} else if (shortcut === 'o' || shortcut === 'O') {
// Toggle global bold
const newGlobalBold = !globalBold;
setGlobalBold(newGlobalBold);
Expand All @@ -250,7 +254,7 @@ export const GlobalOverridesMenu: React.FC<GlobalOverridesMenuProps> = ({ settin
globalBold: newGlobalBold
};
onUpdate(updatedSettings);
} else if (input === 'm' || input === 'M') {
} else if (shortcut === 'm' || shortcut === 'M') {
// Toggle minimalist mode
const newMinimalistMode = !minimalistMode;
setMinimalistMode(newMinimalistMode);
Expand All @@ -259,10 +263,10 @@ export const GlobalOverridesMenu: React.FC<GlobalOverridesMenuProps> = ({ settin
minimalistMode: newMinimalistMode
};
onUpdate(updatedSettings);
} else if (input === 'n' || input === 'N') {
} else if (shortcut === 'n' || shortcut === 'N') {
setNumberFormatMode(true);
setNumberFormatKindIndex(0);
} else if (input === 'f' || input === 'F') {
} else if (shortcut === 'f' || shortcut === 'F') {
// Cycle through foreground colors
const nextIndex = (currentFgIndex + 1) % fgColors.length;
const nextFgColor = fgColors[nextIndex];
Expand All @@ -271,21 +275,21 @@ export const GlobalOverridesMenu: React.FC<GlobalOverridesMenuProps> = ({ settin
overrideForegroundColor: nextFgColor === 'none' ? undefined : nextFgColor
};
onUpdate(updatedSettings);
} else if (input === 'g' || input === 'G') {
} else if (shortcut === 'g' || shortcut === 'G') {
// Enter gradient selection mode
setGradientMode(true);
setGradientIndex(0);
setGradientCustomStep(null);
setGradientStartHex('');
setGradientHexInput('');
} else if (input === 'x' || input === 'X') {
} else if (shortcut === 'x' || shortcut === 'X') {
// Clear override foreground color
const updatedSettings = {
...settings,
overrideForegroundColor: undefined
};
onUpdate(updatedSettings);
} else if (input === 'd' || input === 'D') {
} else if (shortcut === 'd' || shortcut === 'D') {
// Cycle through padding sides: both -> left -> right -> both
const paddingSides = DefaultPaddingSideSchema.options;
const currentIndex = paddingSides.indexOf(settings.defaultPaddingSide);
Expand Down
4 changes: 3 additions & 1 deletion src/tui/components/HideStatesEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
HideableState,
WidgetItem
} from '../../types/Widget';
import { getPlainInput } from '../../utils/input-guards';
import {
MERGE_TARGET_HIDDEN_HIDEABLE_STATE,
getEnabledHideStates,
Expand All @@ -27,6 +28,7 @@ export const HideStatesEditor: React.FC<HideStatesEditorProps> = ({ widget, stat
const [enabledKeys, setEnabledKeys] = useState<string[]>(() => getEnabledHideStates(widget, states));

useInput((input, key) => {
const shortcut = getPlainInput(input, key);
if (key.return) {
onComplete(setEnabledHideStates(widget, states, enabledKeys));
} else if (key.escape) {
Expand All @@ -35,7 +37,7 @@ export const HideStatesEditor: React.FC<HideStatesEditorProps> = ({ widget, stat
setSelectedIndex(selectedIndex - 1 < 0 ? states.length - 1 : selectedIndex - 1);
} else if (key.downArrow && states.length > 0) {
setSelectedIndex(selectedIndex + 1 > states.length - 1 ? 0 : selectedIndex + 1);
} else if (input === ' ') {
} else if (shortcut === ' ') {
const state = states[selectedIndex];
if (state) {
setEnabledKeys(enabledKeys.includes(state.key)
Expand Down
4 changes: 3 additions & 1 deletion src/tui/components/LineSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import React, {

import type { Settings } from '../../types/Settings';
import type { WidgetItem } from '../../types/Widget';
import { getPlainInput } from '../../utils/input-guards';
import { moveItem } from '../../utils/move-item';

import { ConfirmDialog } from './ConfirmDialog';
Expand Down Expand Up @@ -87,6 +88,7 @@ const LineSelector: React.FC<LineSelectorProps> = ({

// Handle keyboard input
useInput((input, key) => {
const shortcut = getPlainInput(input, key);
if (showDeleteDialog) {
return;
}
Expand Down Expand Up @@ -116,7 +118,7 @@ const LineSelector: React.FC<LineSelectorProps> = ({
return;
}

switch (input) {
switch (shortcut) {
case 'a':
if (allowEditing) {
appendLine();
Expand Down
18 changes: 11 additions & 7 deletions src/tui/components/PowerlineSeparatorEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
import React, { useState } from 'react';

import type { Settings } from '../../types/Settings';
import { shouldInsertInput } from '../../utils/input-guards';
import {
getPlainInput,
shouldInsertInput
} from '../../utils/input-guards';

export type EditorMode = 'separator' | 'startCap' | 'endCap';

Expand Down Expand Up @@ -113,6 +116,7 @@ export const PowerlineSeparatorEditor: React.FC<PowerlineSeparatorEditorProps> =
};

useInput((input, key) => {
const shortcut = getPlainInput(input, key);
if (hexInputMode) {
// Hex input mode
if (key.escape) {
Expand Down Expand Up @@ -186,7 +190,7 @@ export const PowerlineSeparatorEditor: React.FC<PowerlineSeparatorEditorProps> =
}

updateSeparators(newSeparators, mode === 'separator' ? newInvertBgs : undefined);
} else if (input === 'a' || input === 'A') {
} else if (shortcut === 'a' || shortcut === 'A') {
// Add after current
const newSeparators = [...separators];
const newInvertBgs = mode === 'separator' ? [...invertBgs] : [];
Expand All @@ -209,7 +213,7 @@ export const PowerlineSeparatorEditor: React.FC<PowerlineSeparatorEditorProps> =
updateSeparators(newSeparators, newInvertBgs);
setSelectedIndex(selectedIndex + 1);
}
} else if (input === 'i' || input === 'I') {
} else if (shortcut === 'i' || shortcut === 'I') {
// Insert before current
const newSeparators = [...separators];
const newInvertBgs = mode === 'separator' ? [...invertBgs] : [];
Expand All @@ -232,13 +236,13 @@ export const PowerlineSeparatorEditor: React.FC<PowerlineSeparatorEditorProps> =
updateSeparators(newSeparators, newInvertBgs);
// Keep selection on the newly inserted item (which is now at selectedIndex)
}
} else if ((input === 'd' || input === 'D') && (mode !== 'separator' || separators.length > 1)) {
} else if ((shortcut === 'd' || shortcut === 'D') && (mode !== 'separator' || separators.length > 1)) {
// Delete current (min 1 for separator, no min for caps)
const newSeparators = separators.filter((_, i) => i !== selectedIndex);
const newInvertBgs = mode === 'separator' ? invertBgs.filter((_, i) => i !== selectedIndex) : [];
updateSeparators(newSeparators, newInvertBgs);
setSelectedIndex(Math.min(selectedIndex, Math.max(0, newSeparators.length - 1)));
} else if (input === 'c' || input === 'C') {
} else if (shortcut === 'c' || shortcut === 'C') {
// Clear all
if (mode === 'separator') {
// Reset to default right-facing separator with no inversion
Expand All @@ -247,12 +251,12 @@ export const PowerlineSeparatorEditor: React.FC<PowerlineSeparatorEditorProps> =
updateSeparators([]);
}
setSelectedIndex(0);
} else if (input === 'h' || input === 'H') {
} else if (shortcut === 'h' || shortcut === 'H') {
// Enter hex input mode
setHexInputMode(true);
setHexInput('');
setCursorPos(0);
} else if ((input === 't' || input === 'T') && mode === 'separator') {
} else if ((shortcut === 't' || shortcut === 'T') && mode === 'separator') {
// Toggle background inversion (for all separators in separator mode)
const newInvertBgs = [...invertBgs];
newInvertBgs[selectedIndex] = !(newInvertBgs[selectedIndex] ?? false);
Expand Down
10 changes: 6 additions & 4 deletions src/tui/components/PowerlineSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, { useState } from 'react';

import type { PowerlineConfig } from '../../types/PowerlineConfig';
import type { Settings } from '../../types/Settings';
import { getPlainInput } from '../../utils/input-guards';
import { type PowerlineFontStatus } from '../../utils/powerline';
import { buildEnabledPowerlineSettings } from '../../utils/powerline-settings';

Expand Down Expand Up @@ -173,6 +174,7 @@ export const PowerlineSetup: React.FC<PowerlineSetupProps> = ({
const globalOverrideMessage = hasGlobalFgOverride ? '⚠ Global override for FG active' : null;

useInput((input, key) => {
const shortcut = getPlainInput(input, key);
if (fontInstallMessage || installingFonts) {
if (fontInstallMessage && !key.escape) {
onClearMessage();
Expand All @@ -187,7 +189,7 @@ export const PowerlineSetup: React.FC<PowerlineSetupProps> = ({
if (screen === 'menu') {
if (key.escape) {
onBack();
} else if (input === 't' || input === 'T') {
} else if (shortcut === 't' || shortcut === 'T') {
if (!powerlineConfig.enabled) {
if (hasManualSeparatorItems) {
setConfirmingEnable(true);
Expand All @@ -203,17 +205,17 @@ export const PowerlineSetup: React.FC<PowerlineSetupProps> = ({
}
});
}
} else if (input === 'i' || input === 'I') {
} else if (shortcut === 'i' || shortcut === 'I') {
setConfirmingFontInstall(true);
} else if ((input === 'a' || input === 'A') && powerlineConfig.enabled) {
} else if ((shortcut === 'a' || shortcut === 'A') && powerlineConfig.enabled) {
onUpdate({
...settings,
powerline: {
...powerlineConfig,
autoAlign: !powerlineConfig.autoAlign
}
});
} else if ((input === 'c' || input === 'C') && powerlineConfig.enabled) {
} else if ((shortcut === 'c' || shortcut === 'C') && powerlineConfig.enabled) {
onUpdate({
...settings,
powerline: {
Expand Down
4 changes: 3 additions & 1 deletion src/tui/components/PowerlineThemeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getPowerlineTheme,
getPowerlineThemes
} from '../../utils/colors';
import { getPlainInput } from '../../utils/input-guards';
import { assignPowerlineThemeSlots } from '../../utils/powerline-theme-index';

import { ConfirmDialog } from './ConfirmDialog';
Expand Down Expand Up @@ -144,14 +145,15 @@ export const PowerlineThemeSelector: React.FC<PowerlineThemeSelectorProps> = ({
}, [selectedIndex, themes]);

useInput((input, key) => {
const shortcut = getPlainInput(input, key);
if (showCustomizeConfirm) {
return;
}

if (key.escape) {
onUpdate(originalSettingsRef.current);
onBack();
} else if (input === 'c' || input === 'C') {
} else if (shortcut === 'c' || shortcut === 'C') {
const currentThemeName = themes[selectedIndex];
if (currentThemeName && currentThemeName !== 'custom') {
setShowCustomizeConfirm(true);
Expand Down
Loading
Loading