diff --git a/src/main/kotlin/app/termora/keymgr/KeyManagerPanel.kt b/src/main/kotlin/app/termora/keymgr/KeyManagerPanel.kt index 9a1170c..7921362 100644 --- a/src/main/kotlin/app/termora/keymgr/KeyManagerPanel.kt +++ b/src/main/kotlin/app/termora/keymgr/KeyManagerPanel.kt @@ -198,12 +198,12 @@ class KeyManagerPanel : JPanel(BorderLayout()) { private fun sshCopyId(evt: AnActionEvent) { val windowScope = evt.getData(DataProviders.WindowScope) ?: return val keyPairs = keyPairTable.selectedRows.map { keyPairTableModel.getOhKeyPair(it) } - val publicKeys = mutableListOf() + val publicKeys = mutableListOf>() for (keyPair in keyPairs) { val publicKey = OhKeyPairKeyPairProvider.generateKeyPair(keyPair).public val baos = ByteArrayOutputStream() OpenSSHKeyPairResourceWriter.INSTANCE.writePublicKey(publicKey, keyPair.name, baos) - publicKeys.add(baos.toString(Charsets.UTF_8)) + publicKeys.add(Pair(keyPair.name, baos.toString(Charsets.UTF_8))) } if (publicKeys.isEmpty()) { diff --git a/src/main/kotlin/app/termora/keymgr/SSHCopyIdDialog.kt b/src/main/kotlin/app/termora/keymgr/SSHCopyIdDialog.kt index 813f2eb..3714aa7 100644 --- a/src/main/kotlin/app/termora/keymgr/SSHCopyIdDialog.kt +++ b/src/main/kotlin/app/termora/keymgr/SSHCopyIdDialog.kt @@ -25,7 +25,8 @@ class SSHCopyIdDialog( owner: Window, private val windowScope: WindowScope, private val hosts: List, - private val publicKeys: List, + // key: name , value: public key + private val publicKeys: List>, ) : DialogWrapper(owner) { companion object { @@ -114,6 +115,9 @@ class SSHCopyIdDialog( var mySession: ClientSession? = null val timeout = Duration.ofMinutes(1) + // 获取公钥名称最长的 + val publicKeyNameLength = publicKeys.maxOfOrNull { it.first.length } ?: 0 + for (index in hosts.indices) { if (!coroutineScope.isActive) { return @@ -125,15 +129,18 @@ class SSHCopyIdDialog( terminal.getDocument().newline() } - for (j in publicKeys.indices) { + for ((j, e) in publicKeys.withIndex()) { if (!coroutineScope.isActive) { return } - val publicKey = publicKeys[j] + val publicKeyName = e.first.padEnd(publicKeyNameLength, ' ') + val publicKey = e.second withContext(Dispatchers.Swing) { - terminal.write("\t[${cyan(j + 1)}/${cyan(publicKeys.size)}] ${I18n.getString("termora.transport.sftp.connecting")}") + // @formatter:off + terminal.write("\t[${cyan(j + 1)}/${cyan(publicKeys.size)}] $publicKeyName ${I18n.getString("termora.transport.sftp.connecting")}") + // @formatter:on } try { @@ -152,12 +159,16 @@ class SSHCopyIdDialog( } withContext(Dispatchers.Swing) { terminal.getDocument().eraseInLine(2) - terminal.write("\r\t[${cyan(j + 1)}/${cyan(publicKeys.size)}] ${green(I18n.getString("termora.keymgr.ssh-copy-id.successful"))}") + // @formatter:off + terminal.write("\r\t[${cyan(j + 1)}/${cyan(publicKeys.size)}] $publicKeyName ${green(I18n.getString("termora.keymgr.ssh-copy-id.successful"))}") + // @formatter:on } } catch (e: Exception) { withContext(Dispatchers.Swing) { terminal.getDocument().eraseInLine(2) - terminal.write("\r\t[${cyan(j + 1)}/${cyan(publicKeys.size)}] ${red("${I18n.getString("termora.keymgr.ssh-copy-id.failed")}: ${e.message}")}") + // @formatter:off + terminal.write("\r\t[${cyan(j + 1)}/${cyan(publicKeys.size)}] $publicKeyName ${red("${I18n.getString("termora.keymgr.ssh-copy-id.failed")}: ${e.message}")}") + // @formatter:on } } finally { IOUtils.closeQuietly(mySession)