Skip to content

Commit a5111a5

Browse files
author
Rustem Galiullin
committed
refactor code as requested
1 parent 98b6345 commit a5111a5

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

lua/leetcode-ui/layout/console.lua

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,6 @@ function ConsoleLayout:set_keymaps(keymaps)
7373
end
7474
end
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-
9876
---@param parent lc.ui.Question
9977
function ConsoleLayout:init(parent)
10078
self.question = parent

lua/leetcode/command/init.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,22 @@ function cmd.open()
250250
local utils = require("leetcode.utils")
251251
utils.auth_guard()
252252
local q = utils.curr_question()
253-
if q then q.console:open_url() end
253+
254+
if q then
255+
local command
256+
local os_name = vim.loop.os_uname().sysname
257+
258+
if os_name == "Linux" then
259+
command = string.format("xdg-open '%s'", q.cache.link)
260+
elseif os_name == "Darwin" then
261+
command = string.format("open '%s'", q.cache.link)
262+
else
263+
-- Fallback to Windows if uname is not available or does not match Linux/Darwin.
264+
command = string.format("start \"\" \"%s\"", q.cache.link)
265+
end
266+
267+
vim.cmd("!" .. command)
268+
end
254269
end
255270

256271
function cmd.fix()

0 commit comments

Comments
 (0)