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

Commit d1f7877

Browse files
authored
Merge pull request #82 from exoego/tty
Overhaul tty module
2 parents 4d43147 + d505ce8 commit d1f7877

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
v12.10.0
2+
v12.10.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The following core Node.js modules (v8.7.0+) have been implemented:
4343
| [stream](https://nodejs.org/api/stream.html) | :heavy_check_mark: |
4444
| [string-decoder](https://nodejs.org/api/string_decoder.html) | :heavy_check_mark: |
4545
| [timers](https://nodejs.org/api/timers.html) | :heavy_check_mark: |
46-
| [tty](https://nodejs.org/api/tty.html) | |
46+
| [tty](https://nodejs.org/api/tty.html) | :heavy_check_mark: |
4747
| [url](https://nodejs.org/api/url.html) | :heavy_check_mark: |
4848
| [util](https://nodejs.org/api/util.html) | :heavy_check_mark: |
4949
| [vm](https://nodejs.org/api/vm.html) | |

app/current/src/main/scala/io/scalajs/nodejs/tty/ReadStream.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package io.scalajs.nodejs.tty
22

3-
import io.scalajs.RawOptions
43
import io.scalajs.nodejs.FileDescriptor
5-
import io.scalajs.nodejs.net.Socket
4+
import io.scalajs.nodejs.net
65

76
import scala.scalajs.js
87
import scala.scalajs.js.annotation.JSImport
@@ -15,7 +14,7 @@ import scala.scalajs.js.annotation.JSImport
1514
*/
1615
@js.native
1716
@JSImport("tty", "ReadStream")
18-
class ReadStream(fd: FileDescriptor, options: RawOptions = js.native) extends Socket {
17+
class ReadStream(fd: FileDescriptor) extends net.Socket {
1918

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

3029
/**
3130
* Indicates whether the stream is a TTY

app/current/src/main/scala/io/scalajs/nodejs/tty/WriteStream.scala

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package io.scalajs.nodejs.tty
22

3+
import com.thoughtworks.enableIf
34
import io.scalajs.nodejs.FileDescriptor
4-
import io.scalajs.nodejs.net.Socket
5+
import io.scalajs.nodejs.net
56

67
import scala.scalajs.js
78
import scala.scalajs.js.annotation.JSImport
@@ -15,11 +16,7 @@ import scala.scalajs.js.annotation.JSImport
1516
*/
1617
@js.native
1718
@JSImport("tty", "WriteStream")
18-
class WriteStream(fd: FileDescriptor) extends Socket {
19-
20-
/////////////////////////////////////////////////////////////////////////////////
21-
// Properties
22-
/////////////////////////////////////////////////////////////////////////////////
19+
class WriteStream(fd: FileDescriptor) extends net.Socket {
2320

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

29+
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
30+
def clearLine(dir: Int, callback: js.Function): Boolean = js.native
31+
// TODO: Return value should be boolean when dropping Node.js v10
32+
def clearLine(dir: Int): Unit = js.native
33+
34+
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
35+
def clearScreenDown(callback: js.Function): Boolean = js.native
36+
// TODO: Return value should be boolean when dropping Node.js v10
37+
def clearScreenDown(): Unit = js.native
38+
39+
// TODO: Return value should be boolean when dropping Node.js v10
40+
def cursorTo(x: Int): Unit = js.native
41+
// TODO: Return value should be boolean when dropping Node.js v10
42+
def cursorTo(x: Int, y: Int): Unit = js.native
43+
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
44+
def cursorTo(x: Int, y: Int, callback: js.Function): Boolean = js.native
45+
46+
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10)
47+
def getColorDepth(env: io.scalajs.nodejs.process.Environment = js.native): Int = js.native
48+
49+
def getWindowSize(): js.Tuple2[Int, Int] = js.native
50+
51+
@enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs12)
52+
def hasColors(count: Int = js.native, env: io.scalajs.nodejs.process.Environment = js.native): Boolean = js.native
53+
3254
/**
3355
* Indicates whether the stream is a TTY
3456
*/
@@ -42,4 +64,9 @@ class WriteStream(fd: FileDescriptor) extends Socket {
4264
*/
4365
def rows: Int = js.native
4466

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

0 commit comments

Comments
 (0)