doucao1066 2012-10-29 23:30
浏览 1419

xterm中的换行问题

I am writing a program that prints colored lines, and the more I do with it the more I find myself working around line wrapping issues that come up.

It is a sort of terminal written in php, here is the prompt:

$return = readline("\033[44m\033[1;37m{$this->text}>>\033[0m ");

and scrolling through history, the non-printing characters play havoc on everything.

If I try to add escapes

$return = readline("\[\033[44m\033[1;37m\]{$this->text}>>\[\033[0m\] ");

then it prints the brackets...even if I add double backslashes.

\[\][timer]>>\[\] 

I find the same thing for echo -e, I am really not sure whats going on.

Lastly, if I modify PS1 it works just fine.

[mike@crest ~]$ export PS1="\[\033[44m\033[1;37m\][timer]>>\[\033[0m\] "
[timer]>>

What am I missing here?

Edit: the coloring/display is not the problem. The problem is that bash will have line wrapping issues when invisible characters are printed without escapes...and when I add the escapes they are printed in plain text under all circumstances but PS1, and I'm not sure what the difference is, how to get it working in PHP.

  • 写回答

1条回答 默认 最新

  • douqianzha6213 2012-10-30 10:54
    关注

    php 1.php

    [TIMER]>>

    <?php
    
    $return = readline("\033[44m\033[1;37m[TIMER]>>\033[0m ");
    
    ?>
    

    Here is dialog example added

    dialog --title "Welcome" --msgbox "
    MY TEST DIALOG 
    
    Press <Enter> to continue or <Esc> to cancel." 10 50
    
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?