Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 仅当接口可用时才激活.widgets.net小部件_Lua_Awesome Wm - Fatal编程技术网

Lua 仅当接口可用时才激活.widgets.net小部件

Lua 仅当接口可用时才激活.widgets.net小部件,lua,awesome-wm,Lua,Awesome Wm,我在我的rc.lua中使用了以下小部件: -- Initialize widget Ethernet ethwidget = wibox.widget.textbox() -- Register widget vicious.re

我在我的
rc.lua
中使用了以下小部件:

-- Initialize widget Ethernet
ethwidget = wibox.widget.textbox()                                                                                                                            
-- Register widget       
    vicious.register(ethwidget, vicious.widgets.net, 'Eth0: <span color="#CC9933">down: ${eth0 down_kb} kB/s</span> <span color="#7F9F7F"> up: ${eth0 up_kb}  kB/s</span><span color="#cccccc"> [ ${eth0 rx_gb} GB //  ${eth0 tx_gb} GB ] | </span>', 2)
——初始化小部件以太网
ethwidget=wibox.widget.textbox()
--注册小部件
register(ethwidget,vicial.widgets.net,'Eth0:down:${Eth0 down_kb}kb/s up:${Eth0 up_kb}kb/s[${Eth0 rx_gb}gb/${Eth0 tx_gb}gb]|,2)

问题是,我有一台最新的macbook pro,如果我没有插上电源,那么我只能在我的wibox上看到例如
${eth0 down\u kb}
。我怎样才能添加一个条件,使小部件仅在以太网适配器插入时插入?

我提供了一个工作正常的解决方案。我找到了这个链接,我的代码如下:

eths = { 'eth0', 'wlp3s0' }
netwidget = wibox.widget.textbox()
vicious.register( netwidget, vicious.widgets.net,
function(widget,args)
t=''  
for i = 1, #eths do
e = eths[i]       
if args["{"..e.." carrier}"] == 1 then
    if e == 'wlp3s0' then
        t=t..'|'..'Wifi: <span color="#CC9933"> down: '..args['{'..e..' down_kb}']..' kbps</span>  <span color="#7F9F7F">up: ' ..args['{'..e..' up_kb}']..'   kbps </span>'..'[ '..args['{'..e..' rx_gb}'].. ' GB // ' ..args['{'..e..' tx_gb}']..' GB ] '
    else          
        t=t..'|'..'Eth0: <span color="#CC9933"> down: '..args['{'..e..' down_kb}']..' kbps</span>  <span color="#7F9F7F">up: ' ..args['{'..e..' up_kb}']..'   kbps </span>'..'[ '..args['{'..e..' rx_gb}'].. ' GB // ' ..args['{'..e..' tx_gb}']..' GB ] '
    end
end
end               
if string.len(t)>0 then -- remove leading '|'
return string.sub(t,2,-1)
end               
return 'No network'
end                                                                                                                                                           
, 1 )

我提出了一个很好的解决方案。我找到了这个链接,我的代码如下:

eths = { 'eth0', 'wlp3s0' }
netwidget = wibox.widget.textbox()
vicious.register( netwidget, vicious.widgets.net,
function(widget,args)
t=''  
for i = 1, #eths do
e = eths[i]       
if args["{"..e.." carrier}"] == 1 then
    if e == 'wlp3s0' then
        t=t..'|'..'Wifi: <span color="#CC9933"> down: '..args['{'..e..' down_kb}']..' kbps</span>  <span color="#7F9F7F">up: ' ..args['{'..e..' up_kb}']..'   kbps </span>'..'[ '..args['{'..e..' rx_gb}'].. ' GB // ' ..args['{'..e..' tx_gb}']..' GB ] '
    else          
        t=t..'|'..'Eth0: <span color="#CC9933"> down: '..args['{'..e..' down_kb}']..' kbps</span>  <span color="#7F9F7F">up: ' ..args['{'..e..' up_kb}']..'   kbps </span>'..'[ '..args['{'..e..' rx_gb}'].. ' GB // ' ..args['{'..e..' tx_gb}']..' GB ] '
    end
end
end               
if string.len(t)>0 then -- remove leading '|'
return string.sub(t,2,-1)
end               
return 'No network'
end                                                                                                                                                           
, 1 )