From 5a3e87fb2d868b6eb9dc1f2636b7c541da707f76 Mon Sep 17 00:00:00 2001 From: imkiva Date: Tue, 11 Sep 2018 00:27:36 +0800 Subject: [PATCH] feature: start working on auto-completion --- .../provider/FileCompletionProvider.kt | 2 +- .../frontend/completion/CompletionManager.kt | 2 +- .../session/shell/ShellTermSession.kt | 2 +- .../shell/client/TermCompleteListener.kt | 4 ++-- .../frontend/terminal/TerminalView.java | 3 ++- .../setup/connections/AssetsFileConnection.kt | 20 ------------------- .../setup/connections/BackupFileConnection.kt | 2 +- .../setup/connections/LocalFileConnection.kt | 2 +- .../setup/connections/OfflineConnection.kt | 6 +++--- .../java/io/neoterm/ui/setup/SetupActivity.kt | 5 +---- .../io/neoterm/ui/support/AboutActivity.kt | 13 +++++++++++- .../io/neoterm/ui/term/tab/NeoTabDecorator.kt | 14 +++++++++++++ .../java/io/neoterm/utils/NetworkUtils.kt | 2 +- app/src/main/res/layout/ui_about.xml | 2 +- app/src/main/res/layout/ui_setup.xml | 6 ------ app/src/main/res/values-zh-rCN/strings.xml | 4 ++-- app/src/main/res/values/strings.xml | 4 ++-- 17 files changed, 45 insertions(+), 48 deletions(-) delete mode 100644 app/src/main/java/io/neoterm/setup/connections/AssetsFileConnection.kt diff --git a/app/src/main/java/io/neoterm/component/completion/provider/FileCompletionProvider.kt b/app/src/main/java/io/neoterm/component/completion/provider/FileCompletionProvider.kt index ae406f2..daaae32 100644 --- a/app/src/main/java/io/neoterm/component/completion/provider/FileCompletionProvider.kt +++ b/app/src/main/java/io/neoterm/component/completion/provider/FileCompletionProvider.kt @@ -26,7 +26,7 @@ open class FileCompletionProvider : ICandidateProvider { } override fun canComplete(text: String): Boolean { - return text.startsWith(File.separatorChar) + return text.startsWith(File.separatorChar) || text.startsWith("\\./") } private fun listDirectory(path: File, filter: ((File) -> Boolean)?): Array { diff --git a/app/src/main/java/io/neoterm/frontend/completion/CompletionManager.kt b/app/src/main/java/io/neoterm/frontend/completion/CompletionManager.kt index b1f2aad..2260646 100644 --- a/app/src/main/java/io/neoterm/frontend/completion/CompletionManager.kt +++ b/app/src/main/java/io/neoterm/frontend/completion/CompletionManager.kt @@ -10,7 +10,7 @@ object CompletionManager { private val candidateProviders = mutableMapOf() fun registerProvider(provider: ICandidateProvider) { - this.candidateProviders.put(provider.providerName, provider) + this.candidateProviders[provider.providerName] = provider } fun unregisterProvider(providerName: String) { diff --git a/app/src/main/java/io/neoterm/frontend/session/shell/ShellTermSession.kt b/app/src/main/java/io/neoterm/frontend/session/shell/ShellTermSession.kt index 1a9bb19..3e96e0e 100644 --- a/app/src/main/java/io/neoterm/frontend/session/shell/ShellTermSession.kt +++ b/app/src/main/java/io/neoterm/frontend/session/shell/ShellTermSession.kt @@ -199,7 +199,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String, val langEnv = "LANG=en_US.UTF-8" val pathEnv = "PATH=" + buildPathEnv() val ldEnv = "LD_LIBRARY_PATH=" + buildLdLibraryEnv() - val pwdEnv = "PWD=" + selectedCwd + val pwdEnv = "PWD=$selectedCwd" val tmpdirEnv = "TMPDIR=${NeoTermPath.USR_PATH}/tmp" diff --git a/app/src/main/java/io/neoterm/frontend/session/shell/client/TermCompleteListener.kt b/app/src/main/java/io/neoterm/frontend/session/shell/client/TermCompleteListener.kt index 2689773..a588c8e 100644 --- a/app/src/main/java/io/neoterm/frontend/session/shell/client/TermCompleteListener.kt +++ b/app/src/main/java/io/neoterm/frontend/session/shell/client/TermCompleteListener.kt @@ -9,6 +9,7 @@ import io.neoterm.frontend.completion.listener.OnCandidateSelectedListener import io.neoterm.frontend.completion.model.CompletionCandidate import io.neoterm.frontend.completion.model.CompletionResult import io.neoterm.frontend.completion.view.CandidatePopupWindow +import io.neoterm.frontend.logging.NLog import io.neoterm.frontend.terminal.TerminalView import java.util.* @@ -72,7 +73,7 @@ class TermCompleteListener(var terminalView: TerminalView?) : OnAutoCompleteList val deleteLength = newText.indexOf(textNeedCompletion) + textNeedCompletion.length if (deleteLength > 0) { - for (i in 0..deleteLength - 1) { + for (i in 0 until deleteLength) { session.write("\b") popChar() } @@ -85,7 +86,6 @@ class TermCompleteListener(var terminalView: TerminalView?) : OnAutoCompleteList pushString(newText) session.write(newText) - // Trigger next completion lastCompletedIndex = inputStack.size triggerCompletion() diff --git a/app/src/main/java/io/neoterm/frontend/terminal/TerminalView.java b/app/src/main/java/io/neoterm/frontend/terminal/TerminalView.java index 286a7a7..fb41bdd 100755 --- a/app/src/main/java/io/neoterm/frontend/terminal/TerminalView.java +++ b/app/src/main/java/io/neoterm/frontend/terminal/TerminalView.java @@ -1009,7 +1009,8 @@ public final class TerminalView extends View { ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); menu.add(Menu.NONE, 1, Menu.NONE, R.string.copy_text).setShowAsAction(show); menu.add(Menu.NONE, 2, Menu.NONE, R.string.paste_text).setEnabled(clipboard.hasPrimaryClip()).setShowAsAction(show); -// menu.add(Menu.NONE, 3, Menu.NONE, R.string.text_selection_more); + menu.add(Menu.NONE, 3, Menu.NONE, R.string.text_selection_more); + return true; } diff --git a/app/src/main/java/io/neoterm/setup/connections/AssetsFileConnection.kt b/app/src/main/java/io/neoterm/setup/connections/AssetsFileConnection.kt deleted file mode 100644 index 8470b78..0000000 --- a/app/src/main/java/io/neoterm/setup/connections/AssetsFileConnection.kt +++ /dev/null @@ -1,20 +0,0 @@ -package io.neoterm.setup.connections - -import io.neoterm.App -import io.neoterm.setup.SetupHelper -import io.neoterm.utils.AssetsUtils -import java.io.IOException -import java.io.InputStream - -/** - * @author kiva - */ - -class AssetsFileConnection : OfflineConnection() { - @Throws(IOException::class) - override fun openInputStream(): InputStream { - val arch = SetupHelper.determineArchName() - val fileName = "offline_setup/$arch.zip" - return AssetsUtils.openAssetsFile(App.get(), fileName) - } -} diff --git a/app/src/main/java/io/neoterm/setup/connections/BackupFileConnection.kt b/app/src/main/java/io/neoterm/setup/connections/BackupFileConnection.kt index 5308c0a..da71aeb 100644 --- a/app/src/main/java/io/neoterm/setup/connections/BackupFileConnection.kt +++ b/app/src/main/java/io/neoterm/setup/connections/BackupFileConnection.kt @@ -7,4 +7,4 @@ import android.net.Uri * @author kiva */ -class BackupFileConnection(context: Context, uri: Uri) : OfflineUriConnection(context, uri) +class BackupFileConnection(context: Context, uri: Uri) : LocalFileConnection(context, uri) diff --git a/app/src/main/java/io/neoterm/setup/connections/LocalFileConnection.kt b/app/src/main/java/io/neoterm/setup/connections/LocalFileConnection.kt index 2b50d4c..37f1dbb 100644 --- a/app/src/main/java/io/neoterm/setup/connections/LocalFileConnection.kt +++ b/app/src/main/java/io/neoterm/setup/connections/LocalFileConnection.kt @@ -7,4 +7,4 @@ import android.net.Uri * @author kiva */ -class LocalFileConnection(context: Context, uri: Uri) : OfflineUriConnection(context, uri) +open class LocalFileConnection(context: Context, uri: Uri) : OfflineUriConnection(context, uri) diff --git a/app/src/main/java/io/neoterm/setup/connections/OfflineConnection.kt b/app/src/main/java/io/neoterm/setup/connections/OfflineConnection.kt index 85d0d30..70db119 100644 --- a/app/src/main/java/io/neoterm/setup/connections/OfflineConnection.kt +++ b/app/src/main/java/io/neoterm/setup/connections/OfflineConnection.kt @@ -24,11 +24,11 @@ abstract class OfflineConnection : SourceConnection { override fun getSize(): Int { if (inputStream != null) { - try { - return inputStream!!.available() + return try { + inputStream!!.available() } catch (e: IOException) { e.printStackTrace() - return 0 + 0 } } diff --git a/app/src/main/java/io/neoterm/ui/setup/SetupActivity.kt b/app/src/main/java/io/neoterm/ui/setup/SetupActivity.kt index 3c6757e..91ee6be 100644 --- a/app/src/main/java/io/neoterm/ui/setup/SetupActivity.kt +++ b/app/src/main/java/io/neoterm/ui/setup/SetupActivity.kt @@ -15,7 +15,6 @@ import io.neoterm.frontend.config.NeoTermPath import io.neoterm.setup.ResultListener import io.neoterm.setup.SetupHelper import io.neoterm.setup.SourceConnection -import io.neoterm.setup.connections.AssetsFileConnection import io.neoterm.setup.connections.BackupFileConnection import io.neoterm.setup.connections.LocalFileConnection import io.neoterm.setup.connections.NetworkConnection @@ -41,7 +40,6 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener, ResultListener private val hintMapping = arrayOf( R.id.setup_method_online, R.string.setup_hint_online, R.id.setup_method_local, R.string.setup_hint_local, - R.id.setup_method_assets, R.string.setup_hint_assets, R.id.setup_method_backup, R.string.setup_hint_backup ) @@ -69,7 +67,6 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener, ResultListener findViewById(R.id.setup_method_online).setOnCheckedChangeListener(onCheckedChangeListener) findViewById(R.id.setup_method_local).setOnCheckedChangeListener(onCheckedChangeListener) - findViewById(R.id.setup_method_assets).setOnCheckedChangeListener(onCheckedChangeListener) findViewById(R.id.setup_method_backup).setOnCheckedChangeListener(onCheckedChangeListener) findViewById