chore: separate connect command

This commit is contained in:
əlemi 2024-08-24 01:57:00 +02:00
parent 380257945e
commit 83c2a2c7e4
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 26 additions and 11 deletions

24
src/client.lua Normal file
View file

@ -0,0 +1,24 @@
local native = require("codemp.loader").load()
local window = require("codemp.window")
local session = require("codemp.session")
local workspace = require("codemp.workspace")
local function connect(host, bang)
if host == nil then host = 'http://codemp.alemi.dev:50054' end
local user, password
if bang then -- ignore configured values
user = vim.fn.input("username > ", "")
password = vim.fn.input("password > ", "")
else
user = vim.g.codemp_username or vim.fn.input("username > ", "")
password = vim.g.codemp_password or vim.fn.input("password > ", "")
end
session.client = native.connect(host, user, password):await()
session.available = workspace.list(session.client)
window.update()
print(" ++ connected to " .. host .. " as " .. user)
end
return {
connect = connect
}

View file

@ -3,6 +3,7 @@ local buffers = require('codemp.buffers')
local workspace = require('codemp.workspace')
local utils = require('codemp.utils')
local window = require('codemp.window')
local client = require("codemp.client")
local native = require('codemp.loader').load()
@ -19,17 +20,7 @@ end
-- always available
local base_actions = {
connect = function(host, bang)
if host == nil then host = 'http://codemp.alemi.dev:50053' end
local user, password
if bang then -- ignore configured values
user = vim.fn.input("username > ", "")
password = vim.fn.input("password > ", "")
else
user = vim.g.codemp_username or vim.fn.input("username > ", "")
password = vim.g.codemp_password or vim.fn.input("password > ", "")
end
state.client = native.connect(host, user, password):await()
print(" ++ connected to " .. host .. " as " .. user)
client.connect(host, bang)
end,
}