I want to create a CLI/terminal-based application ...
# getting-started
d
I want to create a CLI/terminal-based application like vim for editing files. It does not need to be as complex as vim. I can be like nano too. But i don't how to start. In python and Javascript there are many libraries to create UI for terminal interface. But how to build this in kotlin. i have figured that I have to use ncurses.
l
There’s definitely options. If you like compose, you can take a look at mosaic,, you can look at clikt, you can use cinterop with ncurses. For commands with flags, you can use kotlinx-cli
d
is it possible to use kotlin without intellij? Like in c++, we can create a cpp file and then from terminal use compiler like clang.
l
You can use gradlew tasks, or you can use the kotlinc cli compiler.
d
can u point me to some resources for reference
l
kotlinc doesn’t have much documentation, so if the project is more than one file, I’d use gradle still, but I’ve used kotlinc before.
e
just check out any Kotlin project, it almost certainly uses Gradle
a
the Kotlin command line compiler has docs here: https://kotlinlang.org/docs/command-line.html
l
Here's a reference for the cli compiler. Some notes: There’s different commands for the different compilers (kotlinc for JVM, kotlinc-native for Native, and I believe kotlinc-js for JS). You have to pass in all Kotlin files at once. In C++, you compile one file at a time, then link at the end. You pass all at once in Kotlin
d
what should I use maven or gradle? I am new to these.
G 1
e
the Kotlin Gradle Plugin is supported as the primary way to use Kotlin. the Maven plugin… less so
1
l
Depends on what you’re most familiar with. I use gradle typically, but maven should work fine.
I would use IntelliJ to create the project personally. After that, you can just use gradle to build/run. You can run
gradle tasks
and it wll print out a list of tasks the project can run.
a
there’s a guide on how to set up a Kotlin project here: https://kotlinlang.org/docs/jvm-get-started.html the Kotlin Koans are also a good intro https://play.kotlinlang.org/koans/overview
👍 1
d
If I want to start a kotlin project, can i do it without using itellij??? How can I? I like the IDE. But I like to do things first by my own hands to get familiar with the process and also know how everything works under the hood.
l
Will this project be Koltin/Native or Kotlin/JVM?
d
Kotlin/JVM simple cli application...
l
create a folder for the project, then create build.gradle.kts (file) and src (folder). Add
Copy code
plugins {
    kotlin("jvm") version "1.8.10"
    application
}
to the build.gradle.kts and create main.kt in src. Copy
Copy code
fun main() {
    println("What's your name?")
    val name = readln()
    println("Hello, $name!")
}
into main.kt and you should have the most basic project.
If you have gradle installed, run
gradle tasks
and see what the output says. If you don’t then copy the gradle folder and gradlew (gradlew.bat for Windows) from another project.
d
after this, how can I run and compile the code to create a exe?
l
When you run gradle tasks (or gradlew tasks if using the wrapper), it will list the tasks you can use. There should be a few tasks related to building. If everything was set up right,
gradle build
(or gradlew if using the wrapper) should work.
a
if you install Gradle, then run
gradle init
in an empty dir it will guide you through setting up a basic project - you can select ‘Kotlin application’
💯 1
👍 1
but…. just use IntelliJ. It doesn’t set up that many files, and the guide answers the questions you’re asking. Then you can ask about anything that’s not covered.
d
IntelliJ is very useful. But I just want to be able to do stuff without the IDE. I like to use my hands for the first few times to just practise and know the process.
l
In that case, either gradle init or following the steps I mentioned will help with understanding better.
👀 1
Once the project is set up, I’d use IJ, though, since it gives syntax highlighting, refactoring tools, and suggestions.
e
I write all my projects by hand, but Gradle is complex enough that I think you'll have an easier time starting off in the IDE first. https://docs.gradle.org/current/userguide/userguide.html is fairly comprehensive (for everything built-in to Gradle, not Kotlin) but it is a lot to ingest
a
k
You don’t need to send individual questions to the entire channel. You’re already getting answers here.
👍 1
Not sure which parts are you referring to as “and also know how everything works under the hood”. Building things from command line vs building things in the IDE is kinda the same. You either copy-paste the right incantation for the compiler and all its flags in the terminal every single time, or you click the build button in the IDE. Unless maybe you type the build command manually every single time? As for under the hood, unless you’re going under the actual hood to see what the Kotlin compiler does to generate bytecode, and how the JVM interprets that bytecode to run on the specific hardware, is it really under the hood?
d
I just want to know what happens when I click the run button or the build button. Like most people i also started learning kotlin from the IDE.
l
I’d say there is value in at least understanding the command line compiler. I worked on a side project in the early days of Kotlin/Native where I had to pass flags down to the clang build step, or where I had to use a custom LLVM build step, so I needed the Kotlin compiler to produce LLVM bitcode. I was very glad to have had practice with the command line compiler before that.
Most IDE features map pretty close to a gradle task. When you click ‘clean project’, it runs gradle clean, when you click ‘build project’, it runs gradle build. When you click run, it may start a gradle run task or a build, then run the built executable. Sometimes, it will pass in a flag or two (like for debug runs).
🙌 1
d
thanks for helping, all of you. I have set up an initial project from CLI. And now I am in 1 of my favorite place "NVIM". I know it is not suitable for large-scale Kotlin projects.... but I am just learning and exploring now...
👍 2
141 Views