fix(Termux): 修复按钮命令未执行及返回值反转问题
- 移除 stdbuf bash 占位,改为执行命令后进入交互终端 - 替换 \n 为 ; 以支持多行命令分段执行 - 修复 executeTerminalCommand 返回值反转逻辑 - MyTermuxActivity列表文字颜色 white→black 适配浅色主题
This commit is contained in:
@@ -230,7 +230,7 @@ public class MyTermuxActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
TermuxButtonModel model = mButtonList.get(position);
|
TermuxButtonModel model = mButtonList.get(position);
|
||||||
tv.setText(model.getButtonName() + "\n" + model.getExeCommand());
|
tv.setText(model.getButtonName() + "\n" + model.getExeCommand());
|
||||||
tv.setTextColor(getResources().getColor(android.R.color.white));
|
tv.setTextColor(getResources().getColor(android.R.color.black));
|
||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,21 +202,16 @@ public class TermuxCommandExecutor {
|
|||||||
targetCmd += "source ~/.bashrc && ";
|
targetCmd += "source ~/.bashrc && ";
|
||||||
// 步骤3:显式配置PATH
|
// 步骤3:显式配置PATH
|
||||||
targetCmd += "export PATH=/data/data/com.termux/files/usr/bin:$PATH && ";
|
targetCmd += "export PATH=/data/data/com.termux/files/usr/bin:$PATH && ";
|
||||||
// 步骤4:用stdbuf禁用stdout/stderr缓冲(关键!),执行Gradle命令
|
// 步骤4:将用户输入的字面\n转换为shell命令分隔符,
|
||||||
// -o0:stdout无缓冲;-e0:stderr无缓冲;-i0:stdin无缓冲
|
// 确保"cd ~/Sources\npwd"这类输入能分段执行
|
||||||
//targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " task --all | grep assemble && ";
|
String execCommand = command.replace("\\n", "; ");
|
||||||
//targetCmd += "stdbuf -o0 -e0 -i0 " + gradleFullPath + " -Pandroid.aapt2FromMavenOverride=/data/data/com.termux/files/home/android-sdk/build-tools/34.0.4/aapt2 assembleBetaDebug && ";
|
// 步骤5:执行设定的命令(直接由外层bash解释,避免stdbuf对shell内置命令无效)
|
||||||
targetCmd += "stdbuf -o0 -e0 -i0 bash && ";
|
// 步骤6:命令执行完后用stdbuf启动交互式bash,保持终端可见
|
||||||
// 步骤5:执行成功提示
|
targetCmd += execCommand + "; stdbuf -o0 -e0 -i0 bash";
|
||||||
targetCmd += "echo '\n✅ 命令执行完成!' && echo '\n📌 当前目录:" + projectPath + "' && read -p '按回车键关闭终端...'";
|
|
||||||
|
|
||||||
|
|
||||||
// 4. 执行命令(终端会话模式,唤起Termux窗口)
|
// 4. 执行命令(终端会话模式,唤起Termux窗口)
|
||||||
boolean cmdSuccess = TermuxCommandExecutor.executeTerminalCommand(context, targetCmd);
|
return TermuxCommandExecutor.executeTerminalCommand(context, targetCmd);
|
||||||
if (!cmdSuccess) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user