Linux 在 livecode 中的应用

Linux application in livecode

拼写检查是 Linux 中的默认应用程序。借助该应用程序,我们可以在用户输入数据时检查文本字段的拼写吗?

一些(或许多?)Linux 发行版包含一个名为 spell 的命令行实用程序。如果你运行这个参数是单词,你需要再按一次return,但是如果你用一个文件作为参数,你就不需要再按return。这意味着解决方案可能是:

  1. 将字段的文本写入文件
  2. 运行 来自 LiveCode 的 shell 函数的命令行实用程序,文件作为参数
  3. 解析由 shell 函数 return 编辑的结果

在尝试此操作之前,请在 Linux 上打开终端并输入 spell。按回车键查看命令是否被识别。如果是,那么下面的脚本应该可以工作。

此脚本将字段文本写入文件,对文件进行拼写检查,并将不正确的词return发送到 LiveCode。我还没有测试脚本,您可能需要稍微调整一下。

function spellCheck theText
     // works on Linux only
     if the platform is "Linux" then
          // remove everything that isn't a word
          put replaceText(theText,"[^\w]","") into myWords
          // write clean data to a temporary file
          put the tempName into myTempFile
          put myWords into url ("file:" & myTempFile)
          // call spell with shell
          put "spell" && myTempFile into myShell
          // only return the incorrect words
          put line 2 to -1 of shell(myShell) into myCorrections
          // return the incorrect words to calling handler
          return myCorrections
     else
          // this isn't Linux
          return "error"
     end if
end spellCheck

//theField is the short name of a field
on checkField theField
     // call above function
     put spellCheck(the text of fld theField) into myWords
     // myWords should now contain the incorrect words
     if myWords is not "error" then
          lock screen
          // parse incorrect words and mark them in the field
          repeat with x = 1 to number of words of field theField
               if myWord is among the lines of myWords then
                    // an incorrect word has been found and is marked red
                    set the textColor of word x of fld theField to red
               end if
          end repeat
          unlock screen
     end if
end checkField

用法:checkField shortNameOfTheField