File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,28 @@ function ConsoleLayout:set_keymaps(keymaps)
7373 end
7474end
7575
76+ function ConsoleLayout :open_url ()
77+ local command
78+ local p = io.popen (" uname" )
79+ local os_name
80+
81+ if p then
82+ os_name = p :read (" *l" )
83+ p :close ()
84+ end
85+
86+ if os_name == " Linux" then
87+ command = string.format (" xdg-open '%s'" , self .question .cache .link )
88+ elseif os_name == " Darwin" then
89+ command = string.format (" open '%s'" , self .question .cache .link )
90+ else
91+ -- Fallback to Windows if uname is not available or does not match Linux/Darwin.
92+ command = string.format (" start \"\" \" %s\" " , self .question .cache .link )
93+ end
94+
95+ os.execute (command )
96+ end
97+
7698--- @param parent lc.ui.Question
7799function ConsoleLayout :init (parent )
78100 self .question = parent
Original file line number Diff line number Diff line change @@ -246,6 +246,13 @@ function cmd.ui_languages()
246246 languages :show ()
247247end
248248
249+ function cmd .open ()
250+ local utils = require (" leetcode.utils" )
251+ utils .auth_guard ()
252+ local q = utils .curr_question ()
253+ if q then q .console :open_url () end
254+ end
255+
249256function cmd .fix ()
250257 require (" leetcode.cache.cookie" ).delete ()
251258 require (" leetcode.cache.problemlist" ).delete ()
@@ -373,6 +380,7 @@ cmd.commands = {
373380 daily = { cmd .qot },
374381 fix = { cmd .fix },
375382 yank = { cmd .yank },
383+ open = { cmd .open },
376384
377385 list = {
378386 cmd .problems ,
You can’t perform that action at this time.
0 commit comments