【问题标题】:Shell like application using sbt console使用 sbt 控制台的 Shell 类应用程序
【发布时间】:2016-03-16 17:55:55
【问题描述】:

我想部署一些 scala 代码,用于非常类似于 sbt 控制台 (命令行界面、历史记录等) 并想

  • 自定义
  • 并使其易于部署。

sbt 控制台是否可以与这些更改一起使用:

  • 删除了启动信息消息
  • 删除了 scala 欢迎消息
  • 自定义命令提示符而不是“scala>”为“myApp>”
  • 无法访问本地或全局 ivy/maven 存储库(所有 jar 可用,包括 sbt jar 和依赖项)

有人经过这条路吗?

我试过了 Using sbt to build command line application 但到目前为止没有太大进展 (我猜它的意图是非常相似的情况)

有现成的插件可用吗? 任何其他与 sbt 相关或不相关的工具?

谢谢

【问题讨论】:

    标签: scala sbt


    【解决方案1】:

    实际上,不需要 sbt。要对其进行调整,应该更改 scala 代码。

    【讨论】:

      【解决方案2】:

      对于 sbt “自定义命令提示符”部分,您有一个很好的例子,来自 Patrick Bailey (patmandenver) 的“sbt: Customize the Shell prompt in sbt”。

      创建~/.sbt/0.13/global.sbt 文件:

      vi ~/.sbt/0.13/global.sbt
      

      并将以下内容放入其中。

      shellPrompt := { state =>
        def textColor(color: Int)      = { s"\033[38;5;${color}m" }
        def backgroundColor(color:Int) = { s"\033[48;5;${color}m" }
        def reset                      = { s"\033[0m" }
      
        def formatText(str: String)(txtColor: Int, backColor: Int) = {
          s"${textColor(txtColor)}${backgroundColor(backColor)}${str}${reset}"
        }
        val red    = 1
        val green  = 2
        val yellow = 11
        val white  = 15
        val black  = 16
        val orange = 166
      
        formatText(s"[${name.value}]")(white, orange) +
         "\n " +
         formatText("\u276f")(green, black) +
         formatText("\u276f")(yellow, black) +
         formatText("\u276f ")(red, black)
      }
      

      在 sbt 中运行 reload 然后……

      可以修改/增强/完成以添加您在案例中需要的其他信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-11
        • 2010-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多