简体   繁体   English

如何使用 Purescript 从标准输入获取字符串?

[英]how to get string from stdin using Purescript?

as title says, I want to know about how to get stdin using Purescript.正如标题所说,我想知道如何使用 Purescript 获取标准输入。

I want to input string using my keyboard.我想用我的键盘输入字符串。 that's all.就这样。

in fact, I can find some code just googling this.事实上,我可以通过谷歌搜索找到一些代码。 but nothing runs corretly.但没有什么能正确运行。 they omit import statement or complie error occurs.他们省略了导入语句或发生编译错误。

It could be good if I got full code about stdin.如果我有关于标准输入的完整代码,那就太好了。 thank you谢谢你

module Test.Main where

import Prelude

import Effect (Effect)
import Effect.Console (log)

import Node.ReadLine (prompt, close, setLineHandler, setPrompt,  noCompletion, createConsoleInterface)

main :: Effect Unit
main = do
  interface <- createConsoleInterface noCompletion
  setPrompt "> " interface
  prompt interface
  interface # setLineHandler \s ->
    if s == "quit"
      then close interface
      else do
         log $ "You typed: " <> s
         prompt interface

Source: https://github.com/purescript-node/purescript-node-readline/blob/v6.0.0/test/Main.purs来源: https://github.com/purescript-node/purescript-node-readline/blob/v6.0.0/test/Main.purs

Documentation: https://pursuit.purescript.org/packages/purescript-node-readline文档: https://pursuit.purescript.org/packages/purescript-node-readline

Here is a package for reading from stdin , but it might not work the way you expect with keyboard input.这是用于从stdin读取的 package ,但它可能无法按照您期望的键盘输入方式工作。

https://pursuit.purescript.org/packages/purescript-node-streams-aff https://pursuit.purescript.org/packages/purescript-node-streams-aff

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

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