Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
aca12a56
Commit
aca12a56
authored
Feb 16, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move terminal
parent
1bc39f09
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
75 additions
and
59 deletions
+75
-59
mirai-console-terminal/build.gradle.kts
mirai-console-terminal/build.gradle.kts
+7
-4
mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalLoader.kt
...lin/net/mamoe/mirai/console/MiraiConsoleTerminalLoader.kt
+18
-0
mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
.../kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
+44
-33
mirai-console/build.gradle.kts
mirai-console/build.gradle.kts
+0
-6
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt
...e/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt
+6
-15
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleUIFrontEnd.kt
.../kotlin/net/mamoe/mirai/console/MiraiConsoleUIFrontEnd.kt
+0
-1
No files found.
mirai-console-terminal/build.gradle.kts
View file @
aca12a56
...
...
@@ -8,6 +8,12 @@ plugins {
apply
(
plugin
=
"com.github.johnrengelman.shadow"
)
tasks
.
withType
<
com
.
github
.
jengelman
.
gradle
.
plugins
.
shadow
.
tasks
.
ShadowJar
>()
{
manifest
{
attributes
[
"Main-Class"
]
=
"net.mamoe.mirai.console.MiraiConsoleTerminalLoader"
}
}
val
kotlinVersion
:
String
by
rootProject
.
ext
val
atomicFuVersion
:
String
by
rootProject
.
ext
val
coroutinesVersion
:
String
by
rootProject
.
ext
...
...
@@ -29,12 +35,9 @@ dependencies {
api
(
project
(
":mirai-core"
))
api
(
project
(
":mirai-core-qqandroid"
))
api
(
project
(
":mirai-api-http"
))
api
(
project
(
":mirai-console"
))
runtimeOnly
(
files
(
"../mirai-core-qqandroid/build/classes/kotlin/jvm/main"
))
runtimeOnly
(
files
(
"../mirai-core/build/classes/kotlin/jvm/main"
))
api
(
kotlin
(
"serialization"
))
api
(
group
=
"com.alibaba"
,
name
=
"fastjson"
,
version
=
"1.2.62"
)
api
(
group
=
"org.yaml"
,
name
=
"snakeyaml"
,
version
=
"1.25"
)
api
(
group
=
"com.moandjiezana.toml"
,
name
=
"toml4j"
,
version
=
"0.7.2"
)
api
(
group
=
"com.googlecode.lanterna"
,
name
=
"lanterna"
,
version
=
"3.0.2"
)
api
(
"org.bouncycastle:bcprov-jdk15on:1.64"
)
// classpath is not set correctly by IDE
...
...
mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalLoader.kt
0 → 100644
View file @
aca12a56
package
net.mamoe.mirai.console
import
kotlin.concurrent.thread
class
MiraiConsoleTerminalLoader
{
companion
object
{
@JvmStatic
fun
main
(
args
:
Array
<
String
>)
{
MiraiConsoleTerminalUI
.
start
()
MiraiConsole
.
start
(
MiraiConsoleTerminalUI
)
Runtime
.
getRuntime
().
addShutdownHook
(
thread
(
start
=
false
)
{
MiraiConsole
.
stop
()
})
}
}
}
\ No newline at end of file
mirai-console
/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole
UI.kt
→
mirai-console
-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminal
UI.kt
View file @
aca12a56
...
...
@@ -16,15 +16,18 @@ import kotlinx.coroutines.GlobalScope
import
kotlinx.coroutines.Job
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
net.mamoe.mirai.console.MiraiConsoleUI.LoggerDrawer.cleanPage
import
net.mamoe.mirai.console.MiraiConsoleUI.LoggerDrawer.drawLog
import
net.mamoe.mirai.console.MiraiConsoleUI.LoggerDrawer.redrawLogs
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.console.MiraiConsoleTerminalUI.LoggerDrawer.cleanPage
import
net.mamoe.mirai.console.MiraiConsoleTerminalUI.LoggerDrawer.drawLog
import
net.mamoe.mirai.console.MiraiConsoleTerminalUI.LoggerDrawer.redrawLogs
import
java.awt.Font
import
java.io.OutputStream
import
java.io.PrintStream
import
java.nio.charset.Charset
import
java.util.*
import
java.util.concurrent.ConcurrentLinkedQueue
import
kotlin.concurrent.thread
import
kotlin.system.exitProcess
/**
* 此文件不推荐任何人看
...
...
@@ -37,29 +40,38 @@ import kotlin.concurrent.thread
*
*/
@SuppressWarnings
(
"UNCHECKED"
)
object
MiraiConsoleUI
{
object
MiraiConsoleTerminalUI
:
MiraiConsoleUIFrontEnd
{
val
cacheLogSize
=
50
val
log
=
mutableMapOf
<
Long
,
LimitLinkedQueue
<
String
>>().
also
{
it
[
0L
]
=
LimitLinkedQueue
(
cacheLogSize
)
it
[
2821869985L
]
=
LimitLinkedQueue
(
cacheLogSize
)
override
fun
pushLog
(
identity
:
Long
,
message
:
String
)
{
log
[
identity
]
!!
.
offer
(
message
)
if
(
identity
==
screens
[
currentScreenId
])
{
drawLog
(
message
)
}
}
val
botAdminCount
=
mutableMapOf
<
Long
,
Long
>()
override
fun
prePushBot
(
identity
:
Long
)
{
log
[
identity
]
=
LimitLinkedQueue
(
cacheLogSize
)
botAdminCount
[
identity
]
=
0
screens
.
add
(
identity
)
}
private
val
screens
=
mutableListOf
(
0L
,
2821869985L
)
private
var
currentScreenId
=
0
override
fun
pushBot
(
bot
:
Bot
)
{
//nothing to do
}
override
fun
pushBotAdminStatus
(
identity
:
Long
,
admins
:
List
<
Long
>)
{
botAdminCount
[
identity
]
=
admins
.
size
}
fun
addBotScreen
(
uin
:
Long
)
{
screens
.
add
(
uin
)
log
[
uin
]
=
LimitLinkedQueue
(
cacheLogSize
)
botAdminCount
[
uin
]
=
0
val
log
=
mutableMapOf
<
Long
,
Queue
<
String
>>().
also
{
it
[
0L
]
=
LimitLinkedQueue
(
cacheLogSize
)
}
val
botAdminCount
=
mutableMapOf
<
Long
,
Int
>()
private
val
screens
=
mutableListOf
(
0L
)
private
var
currentScreenId
=
0
lateinit
var
terminal
:
Terminal
...
...
@@ -195,6 +207,9 @@ object MiraiConsoleUI {
)
emptyCommand
()
}
KeyType
.
Escape
->
{
exitProcess
(
0
)
}
else
->
{
if
(
keyStroke
.
character
!=
null
)
{
if
(
keyStroke
.
character
.
toInt
()
==
8
)
{
...
...
@@ -360,22 +375,24 @@ object MiraiConsoleUI {
}
fun
redrawLogs
(
toDraw
:
List
<
String
>)
{
fun
redrawLogs
(
toDraw
:
Queue
<
String
>)
{
//this.cleanPage()
currentHeight
=
6
var
logsToDraw
=
0
var
vara
=
0
val
toPrint
=
mutableListOf
<
String
>()
toDraw
.
forEach
{
val
heightNeed
=
(
it
.
length
/
(
terminal
.
terminalSize
.
columns
-
6
))
+
1
vara
+=
heightNeed
if
(
currentHeight
+
vara
<
terminal
.
terminalSize
.
rows
-
4
)
{
logsToDraw
++
toPrint
.
add
(
it
)
}
else
{
return
@
forEach
}
}
for
(
index
in
0
until
logsToDraw
)
{
drawLog
(
toDraw
[
logsToDraw
-
index
-
1
]
,
false
)
toPrint
.
reversed
().
forEach
{
drawLog
(
it
,
false
)
}
if
(
terminal
is
SwingTerminalFrame
)
{
terminal
.
flush
()
...
...
@@ -383,13 +400,6 @@ object MiraiConsoleUI {
}
}
fun
pushLog
(
uin
:
Long
,
str
:
String
)
{
log
[
uin
]
!!
.
push
(
str
)
if
(
uin
==
screens
[
currentScreenId
])
{
drawLog
(
str
)
}
}
var
commandBuilder
=
StringBuilder
()
fun
redrawCommand
()
{
...
...
@@ -475,13 +485,14 @@ object MiraiConsoleUI {
}
}
class
LimitLinkedQueue
<
T
>(
val
limit
:
Int
=
50
)
:
LinkedList
<
T
>(),
List
<
T
>
{
override
fun
push
(
e
:
T
)
{
)
:
ConcurrentLinkedQueue
<
T
>()
{
override
fun
offer
(
e
:
T
):
Boolean
{
if
(
size
>=
limit
)
{
poll
Last
()
poll
()
}
super
.
push
(
e
)
return
super
.
offer
(
e
)
}
}
\ No newline at end of file
}
mirai-console/build.gradle.kts
View file @
aca12a56
...
...
@@ -8,12 +8,6 @@ plugins {
apply
(
plugin
=
"com.github.johnrengelman.shadow"
)
tasks
.
withType
<
com
.
github
.
jengelman
.
gradle
.
plugins
.
shadow
.
tasks
.
ShadowJar
>()
{
manifest
{
attributes
[
"Main-Class"
]
=
"net.mamoe.mirai.console.MiraiConsoleLoader"
}
}
val
kotlinVersion
:
String
by
rootProject
.
ext
val
atomicFuVersion
:
String
by
rootProject
.
ext
val
coroutinesVersion
:
String
by
rootProject
.
ext
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt
View file @
aca12a56
...
...
@@ -50,7 +50,11 @@ object MiraiConsole {
var
coreVersion
=
"0.15"
val
build
=
"Beta"
fun
start
()
{
lateinit
var
frontEnd
:
MiraiConsoleUIFrontEnd
fun
start
(
frontEnd
:
MiraiConsoleUIFrontEnd
)
{
this
.
frontEnd
=
frontEnd
logger
(
"Mirai-console [v$version $build | core version v$coreVersion] is still in testing stage, majority feature is available"
)
logger
(
"Mirai-console now running under "
+
System
.
getProperty
(
...
...
@@ -283,7 +287,7 @@ object MiraiConsole {
operator
fun
invoke
(
identityStr
:
String
,
identity
:
Long
,
any
:
Any
?
=
null
)
{
if
(
any
!=
null
)
{
MiraiConsoleUI
.
pushLog
(
identity
,
"$identityStr: $any"
)
frontEnd
.
pushLog
(
identity
,
"$identityStr: $any"
)
}
}
}
...
...
@@ -301,18 +305,5 @@ object MiraiConsole {
}
class
MiraiConsoleLoader
{
companion
object
{
@JvmStatic
fun
main
(
args
:
Array
<
String
>)
{
MiraiConsoleUI
.
start
()
MiraiConsole
.
start
()
Runtime
.
getRuntime
().
addShutdownHook
(
thread
(
start
=
false
)
{
MiraiConsole
.
stop
()
})
}
}
}
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleUIFrontEnd.kt
View file @
aca12a56
...
...
@@ -14,7 +14,6 @@ interface MiraiConsoleUIFrontEnd {
* identity:log所属的screen, Main=0; Bot=Bot.uin
*/
fun
pushLog
(
identityString
:
String
,
identity
:
Long
,
message
:
String
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment