Buckets:
NaTo1000/termux-app-bucket / termux-shared /src /main /java /com /termux /shared /shell /ShellUtils.java
| package com.termux.shared.shell; | |
| import androidx.annotation.NonNull; | |
| import androidx.annotation.Nullable; | |
| import com.termux.shared.file.FileUtils; | |
| import com.termux.terminal.TerminalBuffer; | |
| import com.termux.terminal.TerminalEmulator; | |
| import com.termux.terminal.TerminalSession; | |
| import java.lang.reflect.Field; | |
| import java.util.ArrayList; | |
| import java.util.Collections; | |
| import java.util.List; | |
| public class ShellUtils { | |
| /** Get process id of {@link Process}. */ | |
| public static int getPid(Process p) { | |
| try { | |
| Field f = p.getClass().getDeclaredField("pid"); | |
| f.setAccessible(true); | |
| try { | |
| return f.getInt(p); | |
| } finally { | |
| f.setAccessible(false); | |
| } | |
| } catch (Throwable e) { | |
| return -1; | |
| } | |
| } | |
| /** Setup shell command arguments for the execute. */ | |
| public static String[] setupShellCommandArguments( String executable, String[] arguments) { | |
| List<String> result = new ArrayList<>(); | |
| result.add(executable); | |
| if (arguments != null) Collections.addAll(result, arguments); | |
| return result.toArray(new String[0]); | |
| } | |
| /** Get basename for executable. */ | |
| public static String getExecutableBasename( String executable) { | |
| return FileUtils.getFileBasename(executable); | |
| } | |
| /** Get transcript for {@link TerminalSession}. */ | |
| public static String getTerminalSessionTranscriptText(TerminalSession terminalSession, boolean linesJoined, boolean trim) { | |
| if (terminalSession == null) return null; | |
| TerminalEmulator terminalEmulator = terminalSession.getEmulator(); | |
| if (terminalEmulator == null) return null; | |
| TerminalBuffer terminalBuffer = terminalEmulator.getScreen(); | |
| if (terminalBuffer == null) return null; | |
| String transcriptText; | |
| if (linesJoined) | |
| transcriptText = terminalBuffer.getTranscriptTextWithFullLinesJoined(); | |
| else | |
| transcriptText = terminalBuffer.getTranscriptTextWithoutJoinedLines(); | |
| if (transcriptText == null) return null; | |
| if (trim) | |
| transcriptText = transcriptText.trim(); | |
| return transcriptText; | |
| } | |
| } | |
Xet Storage Details
- Size:
- 2.29 kB
- Xet hash:
- 14296d2a76db779934dbf077842dee26a328f1ba124aef1efad6da7e148d4df9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.