【问题标题】:Create a simple pure Pascal-only text editor on Linux在 Linux 上创建一个简单的纯 Pascal 文本编辑器
【发布时间】:2023-01-22 10:05:58
【问题描述】:

好的 ?我想在 Linux 上仅在纯 Pascal 中创建一个简单的文本编辑器,这样我就可以打开一个文件并在程序本身中编辑它,或者在其中创建一个文件并完成已经提到的其余部分。到目前为止我得到的是以下内容:

在下面的代码中,我创建了一个文件,然后在不退出程序的情况下向其中添加了我想要的文本,我只使用 CTRL-Z 退出,但是没有方向箭头的交互作用,无法根据需要编辑文件:

program textos;
uses crt;

var
  file_name: string;
  f: text;
  c: char;
  s: string;
begin
  writeln('Enter the name of the file to create');
  readln(file_name);
  writeln('Enter your text to be recorded in the file ', file_name);
  writeln('End with CTRL-Z followed by ENTER');writeln;
  assign(f, file_name);
  rewrite(f);
  repeat;
    read(c);
    write(f,c);
  until c=#26; {is equivalent to chr(26), which is CTRL-Z}
  close(f);
  writeln('Now look at the file ', file_name, ' in your directory');
  writeln;
  writeln('Reading now from disk line by line and putting on screen:');
  reset(f); {opening for reading}
  while (not eof(f)) do
    begin
      readln(f,s);
      writeln(s);
    end;
end.

我已经搜索过了,但没有找到任何相关的东西,我只是在最后一个案例中才把它留在这里。如果有人可以帮助我,我将不胜感激,谢谢...

【问题讨论】:

    标签: editor pascal


    【解决方案1】:

    当您的终端处于熟化模式时,它会为您解释任何控制字符。 因此,默认情况下,按 Control-Z 会发出 SIGTSTP 来停止您的应用程序。 同样,按下箭头键也会被您的终端拦截和处理。 因此,您无法检查 char 值。

    您首先需要切换到原始的terminal mode。 这允许您在击键发生时检查它们,但您还需要处理其他事情。

    通常你将此任务委托给ncurses 之类的库,因为你不想被诸如与agetty(8)xterm(1) 接口之类的低级事物所困扰。 因此,我也建议您使用图书馆。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 1970-01-01
      • 1970-01-01
      • 2020-07-22
      • 2012-01-03
      • 1970-01-01
      • 2017-03-17
      相关资源
      最近更新 更多