Skip to content

修正bug #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public String[] getPyEnv(Context context, String path, String term, String pyPat
env[14] = "PYTHONSTARTUP="+filesDir+"/lib/python2.7/site-packages/qpy.py";
}

env[6] = "PYTHONOPTIMIZE=2";
env[6] = "PYTHONOPTIMIZE=1";//修复__doc__为None的问题

File td = new File(externalStorage+"/cache");
if (!td.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@

package jackpal.androidterm.emulatorview;

import android.util.Log;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Stack;

import android.util.Log;

/**
* Renders text into a screen. Contains all the terminal-specific knowledge and
Expand Down Expand Up @@ -67,6 +65,7 @@ public void setKeyListener(TermKeyListener l) {
private TranscriptScreen mMainBuffer;
private TranscriptScreen mAltBuffer;
private TranscriptScreen mScreen;
private byte backSpaceType;//退格模式

/**
* The terminal session this emulator is bound to.
Expand Down Expand Up @@ -675,11 +674,16 @@ public void append(byte[] buffer, int base, int length) {

//Log.d(EmulatorDebug.LOG_TAG, "In: '" + EmulatorDebug.bytesToString(buffer, base, length) + "'");


if (EmulatorDebug.bytesToString(buffer, base, length).endsWith(">>> ")) {
//乘着船 修改:不同终端不同退格模式
String s = EmulatorDebug.bytesToString(buffer, base, length);
if (s.contains("\\x08\\x08 \\x08\\x08"))
backSpaceType = 1;//传统退格模式
else
backSpaceType = 0;//自动化退格模式
if (s.endsWith(">>> ")) {
sb = new StringBuffer();
} else if (sb != null) {
sb.append(EmulatorDebug.bytesToString(buffer, base, length)
sb.append(s
.replace("\\x0d", "")
.replace("\\x0a", "")
.replace("\\x08", ""));
Expand Down Expand Up @@ -766,8 +770,9 @@ private void process(byte b, boolean doUTF8) {
}
break;

case 8: // BS
setCursorCol(Math.max(0, mCursorCol - 1));
case 8: // BS 退格
//乘着船 修改:修正了不能跨行消除的bug
doBackspace();
break;

case 9: // HT
Expand Down Expand Up @@ -867,6 +872,35 @@ private void process(byte b, boolean doUTF8) {
}
}

private void doBackspace(){ //退格 by 乘着船
if (backSpaceType == 1){ //传统退格模式
setCursorCol(Math.max(mCursorCol-1,0));
return;
}
//自动化退格模式
char[] line; //目标字符串行
int i; //计数变量
int width=0; //单字符宽度
int tWidth=0; //累计字符宽度
if (mCursorCol<=0) { //跨行退格
line = mScreen.getScriptLine(mCursorRow-1);//目标行:上一行
//定位光标到:上一行最后一个字符
setCursorRowCol(mCursorRow-1,line.length-1);
} else { //本行退格
line = mScreen.getScriptLine(mCursorRow);//目标行:本行
}
for (i=0;i<line.length;i++){ //计算累计字符宽度
width=UnicodeTranscript.charWidth(line,i);//获取单字符宽度
tWidth+=width;
//计算最终单个字符宽度:当累计字符宽度>=光标当前位置
if(tWidth>=mCursorCol){
width-=tWidth-mCursorCol;//修正末尾误差
break;
}
}
setCursorCol(mCursorCol-width);//定位当前行光标列位置
}

private boolean handleUTF8Sequence(byte b) {
if (mUTF8ToFollow == 0 && (b & 0x80) == 0) {
// ASCII character -- we don't need to handle this
Expand Down Expand Up @@ -1862,7 +1896,12 @@ private void emit(int c, int style) {
int width = UnicodeTranscript.charWidth(c);

if (autoWrap) {
if (mCursorCol == mColumns - 1 && (mAboutToAutoWrap || width == 2)) {
/*乘着船 修改:
修正中文换行末尾缺字符的bug,
剩一个字符时,或者上次操作剩两个以下字符时(mAboutToAutoWrap变量),
立即换行,避免下个字符是中文,导致超出范围显示不全
*/
if ((mCursorCol >= mColumns - 1) || mAboutToAutoWrap) {
mScreen.setLineWrap(mCursorRow);
mCursorCol = 0;
mJustWrapped = true;
Expand Down Expand Up @@ -1895,7 +1934,9 @@ private void emit(int c, int style) {
}

if (autoWrap) {
mAboutToAutoWrap = (mCursorCol == mColumns - 1);
//乘着船 修改:修正中文换行末尾缺字符的bug,
//剩两个或一个字符时,即可换行,避免下个字符是中文,导致超出范围显示不全
mAboutToAutoWrap = (mCursorCol >= mColumns - 2);

//Force line-wrap flag to trigger even for lines being typed
if (mAboutToAutoWrap)
Expand Down