小编FJD*_*JDU的帖子

屏幕内的vim颜色有256种颜色的奇怪行为

我试图在vim里面screen运行语法高亮(256色)工作gterm.

它在一开始就很好用.我在"开头"的意思是,在我开始之后screen,进入vim,颜色看起来很好,并且有256种颜色.

但是过了一会儿(我不确切知道多长时间)颜色会自动变回外观,好像只有8种(或16种)颜色.

例如,在此之后,如果我输入命令

hi Comment ctermfg=68
Run Code Online (Sandbox Code Playgroud)

在里面vim,评论似乎是"纯粹的"绿色; 但是,如果我打开另一个vim外部屏幕(在同一个终端中),则使用相同的命令,注释看起来是"黄色"绿色.

以下是与颜色相关的.screenrc设置:

attrcolor b ".I"
defbce "on"
termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
term xterm-256color
Run Code Online (Sandbox Code Playgroud)

运行python脚本显示所有颜色后,我发现这可能是屏幕本身的问题,与vim无关.

我所做的是,在screen有问题的会话中,这个脚本给出256种颜色,但其中许多实际上是相同的; 但是,当我使用相同的配置启动新的屏幕会话时,此脚本会提供256种颜色,这两种颜色彼此不同.

编辑:

昨晚我连接到我的Linux计算机(在我的办公室,它总是打开)putty,然后打开一个screen包含多个窗口的会话.昨晚的颜色是正确的.然后在我睡觉前,我分开screen会议并关闭putty.

现在早上当我再次附上那个screen会话putty时,颜色会崩溃:它们看起来好像只有8种颜色.

外面的颜色很好screen(但仍在putty).

编辑:

三年后,在我问这个问题之后,今天我看到了类似的问题.问题是vim可以在外面显示256种颜色screen,并且screen可以用测试脚本显示256种颜色,但vim不能在里面显示任何颜色(只能显示黑白)screen.就像对自己的说明一样,这是.screenrc我正在使用的文件

hardstatus alwayslastline "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} …
Run Code Online (Sandbox Code Playgroud)

vim bash terminal gnu-screen colors

45
推荐指数
2
解决办法
2万
查看次数

如何在python脚本中暂停和等待命令输入

是否有可能在python中有如下的脚本?

...
Pause
->
Wait for the user to execute some commands in the terminal (e.g. 
  to print the value of a variable, to import a library, or whatever).
The script will keep waiting if the user does not input anything.
->
Continue execution of the remaining part of the script
Run Code Online (Sandbox Code Playgroud)

本质上,脚本暂时将控件提供给python命令行解释器,并在用户以某种方式完成该部分后继续.

编辑:我提出的(灵感来自答案)如下所示:

x = 1

i_cmd = 1
while True:
  s = raw_input('Input [{0:d}] '.format(i_cmd))
  i_cmd += 1
  n = len(s)
  if n > 0 and s.lower() == 'break'[0:n]: …
Run Code Online (Sandbox Code Playgroud)

python

16
推荐指数
2
解决办法
7万
查看次数

使用-O1编译时,C ++ regex_search中断

样例代码:

#include <iostream>
#include <string>
#include <regex>

int main()
{
  std::regex npat(R"(^(\d+))");
  std::smatch m;
  std::regex_search(std::string("10"), m, npat);
  std::cout << m.size() << " m.str(1): |"
            << m.str(1) << "| ";
  std::cout << std::stoi(m.str(1)) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

当使用

g++ -std=c++11 main.cpp
Run Code Online (Sandbox Code Playgroud)

输出是

2 m.str(1): |10| 10
Run Code Online (Sandbox Code Playgroud)

这是预期的。

但是,当使用

g++ -std=c++11 -O1 main.cpp
Run Code Online (Sandbox Code Playgroud)

输出变为

libc++abi.dylib: terminating with uncaught exception
of type std::invalid_argument: stoi: no conversion
2 m.str(1): || Abort trap: 6
Run Code Online (Sandbox Code Playgroud)

编译器版本:

g++ -v
Run Code Online (Sandbox Code Playgroud)

配置为:--prefix = / Library / Developer / CommandLineTools / …

c++ regex c++11 clang++

7
推荐指数
1
解决办法
179
查看次数

有条件地从两个列表中选择元素的巧妙方法?

我有两个清单:

a = [-1, 2, 3]
b = ['a', 'b', 'c']
Run Code Online (Sandbox Code Playgroud)

元素的数量ab总是相同的.

我希望保持所有元素a都是正面的,以及相应的元素b.

一种直截了当的方式

anew = []
bnew = []
for i in xrange(len(a)):
    if a[i] > 0:
         anew.append(a[i])
         bnew.append(b[i])
Run Code Online (Sandbox Code Playgroud)

或类似的东西

tmp = zip(*[(a[i], b[i]) for i in xrange(len(a)) if a[i]>0])
a = tmp[0] # The original a and b need not to be kept.
b = tmp[1]
Run Code Online (Sandbox Code Playgroud)

我想知道是否有更短更清洁(没有任何临时变量)的方法.某种就地删除是完美的,但如果我del a[i], b[i]在循环中使用,删除一个元素后索引将是错误的.

编辑:如果选择涉及两个列表,例如条件变为什么,该怎么办?

if a[i] > 0 and b[i] …

python list

4
推荐指数
2
解决办法
1662
查看次数

标签 统计

python ×2

bash ×1

c++ ×1

c++11 ×1

clang++ ×1

colors ×1

gnu-screen ×1

list ×1

regex ×1

terminal ×1

vim ×1