Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Overhaul tty module #82

Merged
merged 2 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
v12.10.0
v12.10.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The following core Node.js modules (v8.7.0+) have been implemented:
| [stream](https://nodejs.org/api/stream.html) | :heavy_check_mark: |
| [string-decoder](https://nodejs.org/api/string_decoder.html) | :heavy_check_mark: |
| [timers](https://nodejs.org/api/timers.html) | :heavy_check_mark: |
| [tty](https://nodejs.org/api/tty.html) | |
| [tty](https://nodejs.org/api/tty.html) | :heavy_check_mark: |
| [url](https://nodejs.org/api/url.html) | :heavy_check_mark: |
| [util](https://nodejs.org/api/util.html) | :heavy_check_mark: |
| [vm](https://nodejs.org/api/vm.html) | |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.scalajs.nodejs.tty

import io.scalajs.RawOptions
import io.scalajs.nodejs.FileDescriptor
import io.scalajs.nodejs.net.Socket
import io.scalajs.nodejs.net

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
Expand All @@ -15,7 +14,7 @@ import scala.scalajs.js.annotation.JSImport
*/
@js.native
@JSImport("tty", "ReadStream")
class ReadStream(fd: FileDescriptor, options: RawOptions = js.native) extends Socket {
class ReadStream(fd: FileDescriptor) extends net.Socket {

/////////////////////////////////////////////////////////////////////////////////
// Properties
Expand All @@ -25,7 +24,7 @@ class ReadStream(fd: FileDescriptor, options: RawOptions = js.native) extends So
* A boolean that is true if the TTY is currently configured to operate as a raw device. Defaults to false.
* @since 0.7.7
*/
var isRaw: Boolean = js.native
def isRaw: Boolean = js.native

/**
* Indicates whether the stream is a TTY
Expand Down
39 changes: 33 additions & 6 deletions app/current/src/main/scala/io/scalajs/nodejs/tty/WriteStream.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.scalajs.nodejs.tty

import com.thoughtworks.enableIf
import io.scalajs.nodejs.FileDescriptor
import io.scalajs.nodejs.net.Socket
import io.scalajs.nodejs.net

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
Expand All @@ -15,11 +16,7 @@ import scala.scalajs.js.annotation.JSImport
*/
@js.native
@JSImport("tty", "WriteStream")
class WriteStream(fd: FileDescriptor) extends Socket {

/////////////////////////////////////////////////////////////////////////////////
// Properties
/////////////////////////////////////////////////////////////////////////////////
class WriteStream(fd: FileDescriptor) extends net.Socket {

/**
* A number specifying the number of columns the TTY currently has. This property is updated whenever
Expand All @@ -29,6 +26,31 @@ class WriteStream(fd: FileDescriptor) extends Socket {
*/
def columns: Int = js.native

@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
def clearLine(dir: Int, callback: js.Function): Boolean = js.native
// TODO: Return value should be boolean when dropping Node.js v10
def clearLine(dir: Int): Unit = js.native

@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
def clearScreenDown(callback: js.Function): Boolean = js.native
// TODO: Return value should be boolean when dropping Node.js v10
def clearScreenDown(): Unit = js.native

// TODO: Return value should be boolean when dropping Node.js v10
def cursorTo(x: Int): Unit = js.native
// TODO: Return value should be boolean when dropping Node.js v10
def cursorTo(x: Int, y: Int): Unit = js.native
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
def cursorTo(x: Int, y: Int, callback: js.Function): Boolean = js.native

@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10)
def getColorDepth(env: io.scalajs.nodejs.process.Environment = js.native): Int = js.native

def getWindowSize(): js.Tuple2[Int, Int] = js.native

@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
def hasColors(count: Int = js.native, env: io.scalajs.nodejs.process.Environment = js.native): Boolean = js.native

/**
* Indicates whether the stream is a TTY
*/
Expand All @@ -42,4 +64,9 @@ class WriteStream(fd: FileDescriptor) extends Socket {
*/
def rows: Int = js.native

// TODO: Return value should be boolean when dropping Node.js v10
def moveCursor(dx: Int, dy: Int): Unit = js.native
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
def moveCursor(dx: Int, dy: Int, callback: js.Function): Boolean = js.native

}