简体   繁体   English

C / Objective-C中的回车符(“\\ r”)在gdb输出中不起作用

[英]Carriage return (“\r”) in C/Objective-C in gdb output not working

I want output to the command line (so far, in the gdb command line within XCode) to overwrite the same line. 我希望输出到命令行(到目前为止,在XCode中的gdb命令行中)覆盖同一行。 The code I'm using to print the output right now takes some things from an Objective-C method and eventually does this: 我现在用于打印输出的代码从Objective-C方法中获取了一些东西,并最终执行此操作:

unsigned char _output = ...;
printf("Output:%c\r",_output);
fflush(stdout);

It prints the correct output, but on successive lines instead of overwriting. 它打印正确的输出,但在连续的行上而不是覆盖。 What could the problem be? 问题是什么?

The GDB console in Xcode is not a full-featured terminal emulation. Xcode中的GDB控制台不是功能齐全的终端仿真。 It's intended to support interaction with GDB, and that's it. 它旨在支持与GDB的交互,就是这样。 How control characters are handled is going to depend on the terminal emulator you use. 如何处理控制字符取决于您使用的终端仿真器。 What happens when you run the tool from the commandline directly using Terminal.app? 使用Terminal.app直接从命令行运行该工具会发生什么? What about xTerm? xTerm怎么样? rxvt? 的rxvt?

The interpretation of '\\r' and '\\n' are up to the platform or terminal. '\\ r'和'\\ n'的解释取决于平台或终端。 Terminals can be set to append a linefeed (0x0a) to a '\\r' automatically. 终端可以设置为自动将换行符(0x0a)附加到'\\ n'。 Also, '\\n', is newline , which can mean either a single linefeed (assuming a carriage return) or a carriage-return and linefeed pair. 另外,'\\ n'是换行符 ,它可以表示单个换行符(假设回车符)或回车符和换行符对。 For portability, one cannot count on a '\\r' to only return the carriage (cursor) to the beginning of the current line. 为了便于携带,人们不能指望'\\ r'只将托架(光标)返回到当前行的开头。

To get to the beginning of the same line, one may be tempted to use '\\b' (backspace). 要到达同一行的开头,可能会想要使用'\\ b'(退格)。 But this is subjective as well. 但这也是主观的。 Some output devices interpret the command as destructive, some as moving backward one character, non-destructive and others will ignore it. 有些输出设备将命令解释为破坏性的,有些则将一个字符向后移动,非破坏性的,其他设备则忽略它。

I suggest you use a cursor positioning library instead. 我建议你使用光标定位库。 Some people recommend NCurses . 有些人推荐NCurses

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM