@@ -6,22 +6,15 @@ import type { Command, ArgumentProviderContext } from "./core/types.js"
66import type { CLIConfig } from "../config/types.js"
77import { getThemeById , getAvailableThemes } from "../constants/themes/index.js"
88import { messageResetCounterAtom } from "../state/atoms/ui.js"
9- import { createStore } from "jotai"
10-
11- /**
12- * Get config from disk
13- */
14- async function getConfig ( ) : Promise < { config : CLIConfig } > {
15- const { loadConfig } = await import ( "../config/persistence.js" )
16- const { config } = await loadConfig ( )
17- return { config }
18- }
199
2010/**
2111 * Autocomplete provider for theme names
2212 */
23- async function themeAutocompleteProvider ( _context : ArgumentProviderContext ) {
24- const { config } = await getConfig ( )
13+ async function themeAutocompleteProvider ( context : ArgumentProviderContext ) {
14+ if ( ! context . commandContext ) {
15+ return [ ]
16+ }
17+ const config = context . commandContext . config
2518 const availableThemeIds = getAvailableThemes ( config )
2619
2720 // Create theme display info array to apply same sorting logic
@@ -36,8 +29,8 @@ async function themeAutocompleteProvider(_context: ArgumentProviderContext) {
3629 }
3730 } )
3831 . sort ( ( a , b ) => {
39- // Sort by type (Dark first, then Light , then Custom ), then by ID alphabetically
40- const typeOrder = { Dark : 0 , Light : 1 , Custom : 2 }
32+ // Sort by type (dark first, then light , then custom ), then by ID alphabetically
33+ const typeOrder = { dark : 0 , light : 1 , custom : 2 }
4134 const typeAOrder = typeOrder [ a . type as keyof typeof typeOrder ] ?? 3
4235 const typeBOrder = typeOrder [ b . type as keyof typeof typeOrder ] ?? 3
4336
@@ -102,7 +95,7 @@ export const themeCommand: Command = {
10295 * Validate theme argument against available themes
10396 */
10497 validate : async ( value , _context ) => {
105- const { config } = await getConfig ( )
98+ const config = _context . commandContext ?. config
10699 const availableThemeIds = getAvailableThemes ( config )
107100 const isValid = availableThemeIds . includes ( value . trim ( ) . toLowerCase ( ) )
108101
@@ -114,8 +107,7 @@ export const themeCommand: Command = {
114107 } ,
115108 ] ,
116109 handler : async ( context ) => {
117- const { args, addMessage, setTheme } = context
118- const { config } = await getConfig ( )
110+ const { args, addMessage, setTheme, config } = context
119111 const availableThemeIds = getAvailableThemes ( config )
120112
121113 try {
@@ -142,7 +134,7 @@ export const themeCommand: Command = {
142134 )
143135
144136 // Define the order for displaying theme types
145- const typeOrder = [ "Dark " , "Light " , "Custom " ]
137+ const typeOrder = [ "dark " , "light " , "custom " ]
146138
147139 // Show interactive theme selection menu
148140 const helpText : string [ ] = [ "**Available Themes:**" , "" ]
@@ -187,25 +179,13 @@ export const themeCommand: Command = {
187179 const themeName = theme . name || requestedTheme
188180
189181 try {
190- await setTheme ( requestedTheme )
191-
192- // Repaint the terminal to immediately show theme changes
193- // Clear the terminal screen and reset cursor position
194- // \x1b[2J - Clear entire screen
195- // \x1b[3J - Clear scrollback buffer (needed for gnome-terminal)
196- // \x1b[H - Move cursor to home position (0,0)
197- process . stdout . write ( "\x1b[2J\x1b[3J\x1b[H" )
198-
199- // Increment reset counter to force UI re-render
200- const store = createStore ( )
201- store . set ( messageResetCounterAtom , ( prev : number ) => prev + 1 )
202-
203182 addMessage ( {
204183 id : Date . now ( ) . toString ( ) ,
205184 type : "system" ,
206185 content : `Switched to **${ themeName } ** theme.` ,
207186 ts : Date . now ( ) ,
208187 } )
188+ setTheme ( requestedTheme )
209189 } catch ( error ) {
210190 addMessage ( {
211191 id : Date . now ( ) . toString ( ) ,
0 commit comments