如何在Shoes中制作简单的文本编辑应用程序?

时间:2022-11-15 20:49:23

I am trying to write a simple tool using Shoes. This will indent code for an obscure scripting language we use. It has one large text box and one button. I have the program working on the command line, but am having no luck wrapping this up in Shoes. If anyone could give a working example of an app that does the following tasks to get me up and running that would be very useful.

我正在尝试使用Shoes编写一个简单的工具。这将缩进我们使用的晦涩脚本语言的代码。它有一个大文本框和一个按钮。我让程序在命令行上运行,但我没有运气将它包装在Shoes中。如果有人可以提供一个应用程序的工作示例,该应用程序执行以下任务以启动并运行这将非常有用。

When the button is clicked I want to: Get the text, split into an array of lines, (indenting happens here), join the lines again and refresh the text box with the new data.

单击按钮时,我想:获取文本,拆分成一个行数组(此处出现缩进),再次连接行并使用新数据刷新文本框。

2 个解决方案

#1


Shoes.app :width => 300, :height => 450 do
  @text = edit_box :width => 1.0, :height => 400
  btn = button 'Indent!'
  btn.click do
    ugly_txt = @text.text
    lines = ugly_txt.split $/ #the record separator
    lines.collect! { |line| '  ' + line } #your indentation would replace this
    @text.text = lines.join $/
  end
end

#2


I think there's an example in the samples folder

我认为samples文件夹中有一个例子

#1


Shoes.app :width => 300, :height => 450 do
  @text = edit_box :width => 1.0, :height => 400
  btn = button 'Indent!'
  btn.click do
    ugly_txt = @text.text
    lines = ugly_txt.split $/ #the record separator
    lines.collect! { |line| '  ' + line } #your indentation would replace this
    @text.text = lines.join $/
  end
end

#2


I think there's an example in the samples folder

我认为samples文件夹中有一个例子