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
a2ae001f
Commit
a2ae001f
authored
Feb 16, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Console Terminal Chinese Supported
parent
168d91e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
28 deletions
+48
-28
mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
.../kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
+47
-27
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/BotConfigurationJvm.kt
...mMain/kotlin/net/mamoe/mirai/utils/BotConfigurationJvm.kt
+1
-1
No files found.
mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
View file @
a2ae001f
...
...
@@ -15,11 +15,13 @@ import com.googlecode.lanterna.terminal.swing.SwingTerminalFrame
import
kotlinx.coroutines.*
import
kotlinx.coroutines.io.close
import
kotlinx.io.core.IoBuffer
import
kotlinx.io.core.use
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
net.mamoe.mirai.utils.LoginSolver
import
net.mamoe.mirai.utils.createCharImg
import
net.mamoe.mirai.utils.writeChannel
import
java.awt.Font
import
java.io.File
...
...
@@ -29,6 +31,7 @@ import java.nio.charset.Charset
import
java.util.*
import
java.util.concurrent.ConcurrentHashMap
import
java.util.concurrent.ConcurrentLinkedDeque
import
javax.imageio.ImageIO
import
kotlin.concurrent.thread
import
kotlin.system.exitProcess
...
...
@@ -156,7 +159,17 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
error
(
"[Login Solver]验证码无法保存[Error0001]"
)
}
}
pushLog
(
0
,
"[Login Solver]请输入 4 位字母验证码. 若要更换验证码, 请直接回车"
)
var
toLog
=
""
tempFile
.
inputStream
().
use
{
val
img
=
ImageIO
.
read
(
it
)
if
(
img
==
null
)
{
toLog
+=
"无法创建字符图片. 请查看文件\n"
}
else
{
toLog
+=
img
.
createCharImg
((
terminal
.
terminalSize
.
columns
/
1.5
).
toInt
())
}
}
pushLog
(
0
,
"$toLog[Login Solver]请输验证码. ${tempFile.absolutePath}"
)
return
requestInput
(
"[Login Solver]请输入 4 位字母验证码. 若要更换验证码, 请直接回车"
)
!!
.
takeUnless
{
it
.
isEmpty
()
||
it
.
length
!=
4
}
.
also
{
...
...
@@ -468,40 +481,47 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
val
maxHeight
=
terminal
.
terminalSize
.
rows
-
4
val
heightNeed
=
(
string
.
actualLength
()
/
(
terminal
.
terminalSize
.
columns
-
6
))
+
1
if
(
heightNeed
-
1
>
maxHeight
)
{
pushLog
(
0
,
"[UI ERROR]: 您的屏幕太小, 有一条超长LOG无法显示"
)
return
//拒绝打印
}
if
(
currentHeight
+
heightNeed
>
maxHeight
)
{
cleanPage
()
cleanPage
()
//翻页
}
val
width
=
terminal
.
terminalSize
.
columns
-
6
var
x
=
string
while
(
true
)
{
if
(
x
==
""
)
break
val
toWrite
=
if
(
x
.
actualLength
()
>
width
)
{
val
index
=
x
.
getSubStringIndexByActualLength
(
width
)
x
.
substring
(
0
,
index
).
also
{
x
=
if
(
index
<
x
.
length
)
{
x
.
substring
(
index
)
}
else
{
""
if
(
string
.
contains
(
"\n"
))
{
string
.
split
(
"\n"
).
forEach
{
drawLog
(
string
,
false
)
}
}
else
{
val
width
=
terminal
.
terminalSize
.
columns
-
6
var
x
=
string
while
(
true
)
{
if
(
x
==
""
)
break
val
toWrite
=
if
(
x
.
actualLength
()
>
width
)
{
val
index
=
x
.
getSubStringIndexByActualLength
(
width
)
x
.
substring
(
0
,
index
).
also
{
x
=
if
(
index
<
x
.
length
)
{
x
.
substring
(
index
)
}
else
{
""
}
}
}
else
{
x
.
also
{
x
=
""
}
}
}
else
{
x
.
also
{
x
=
""
try
{
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
GREEN
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
DEFAULT
textGraphics
.
putString
(
3
,
currentHeight
,
toWrite
,
SGR
.
ITALIC
)
}
catch
(
ignored
:
Exception
)
{
//
}
++
currentHeight
}
try
{
textGraphics
.
foregroundColor
=
TextColor
.
ANSI
.
GREEN
textGraphics
.
backgroundColor
=
TextColor
.
ANSI
.
DEFAULT
textGraphics
.
putString
(
3
,
currentHeight
,
toWrite
,
SGR
.
ITALIC
)
}
catch
(
ignored
:
Exception
)
{
//
}
++
currentHeight
}
if
(
flush
&&
terminal
is
SwingTerminalFrame
)
{
terminal
.
flush
()
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/BotConfigurationJvm.kt
View file @
a2ae001f
...
...
@@ -134,7 +134,7 @@ private val loginSolverLock = Mutex()
/**
* @author NaturalHG
*/
p
rivate
fun
BufferedImage
.
createCharImg
(
outputWidth
:
Int
=
100
,
ignoreRate
:
Double
=
0.95
):
String
{
p
ublic
fun
BufferedImage
.
createCharImg
(
outputWidth
:
Int
=
100
,
ignoreRate
:
Double
=
0.95
):
String
{
val
newHeight
=
(
this
.
height
*
(
outputWidth
.
toDouble
()
/
this
.
width
)).
toInt
()
val
tmp
=
this
.
getScaledInstance
(
outputWidth
,
newHeight
,
Image
.
SCALE_SMOOTH
)
val
image
=
BufferedImage
(
outputWidth
,
newHeight
,
BufferedImage
.
TYPE_INT_ARGB
)
...
...
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