我有一个脚本,我想将其作为单个文件维护,但是我希望在不使用/*
* based on android-21/legacy/ApiDemos/src/com/example/android/apis/view/LabelView.java
*/
public class CustomLabelView extends View {
private final String TAG = getClass().getSimpleName();
private Paint mTextPaint;
private String mText;
private int mAscent;
//tag to identify instance in log
private String mTag;
/**
* Constructor. This version is only needed if you will be instantiating
* the object manually (not from a layout XML file).
*
* @param context
*/
public CustomLabelView(Context context, String tag) {
super(context);
initLabelView();
mTag = tag;
}
private final void initLabelView() {
mTextPaint = new Paint();
mTextPaint.setAntiAlias(true);
// Must manually scale the desired text size to match screen density
mTextPaint.setTextSize(16 * getResources().getDisplayMetrics().density);
mTextPaint.setColor(0xFF000000);
setPadding(3, 3, 3, 3);
}
/**
* Sets the text to display in this label
*
* @param text The text to display. This will be drawn as one line.
*/
public void setText(String text) {
mText = text;
requestLayout();
invalidate();
}
/**
* Sets the text size for this label
*
* @param size Font size
*/
public void setTextSize(int size) {
// This text size has been pre-scaled by the getDimensionPixelOffset method
mTextPaint.setTextSize(size);
requestLayout();
invalidate();
}
/**
* Sets the text color for this label.
*
* @param color ARGB value for the text
*/
public void setTextColor(int color) {
mTextPaint.setColor(color);
invalidate();
}
/**
* @see android.view.View#measure(int, int)
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(measureWidth(widthMeasureSpec),
measureHeight(heightMeasureSpec));
}
/**
* Determines the width of this view
*
* @param measureSpec A measureSpec packed into an int
* @return The width of the view, honoring constraints from measureSpec
*/
private int measureWidth(int measureSpec) {
int result = 0;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
if (specMode == MeasureSpec.EXACTLY) {
// We were told how big to be
result = specSize;
} else {
// Measure the text
result = (int) mTextPaint.measureText(mText) + getPaddingLeft()
+ getPaddingRight();
if (specMode == MeasureSpec.AT_MOST) {
// Respect AT_MOST value if that was what is called for by measureSpec
result = Math.min(result, specSize);
}
}
Log.i(TAG, "(" + mTag + ") measureWidth: result = " + result);
return result;
}
/**
* Determines the height of this view
*
* @param measureSpec A measureSpec packed into an int
* @return The height of the view, honoring constraints from measureSpec
*/
private int measureHeight(int measureSpec) {
int result = 0;
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
mAscent = (int) mTextPaint.ascent();
if (specMode == MeasureSpec.EXACTLY) {
// We were told how big to be
result = specSize;
} else {
// Measure the text (beware: ascent is a negative number)
result = (int) (-mAscent + mTextPaint.descent()) + getPaddingTop()
+ getPaddingBottom();
if (specMode == MeasureSpec.AT_MOST) {
// Respect AT_MOST value if that was what is called for by measureSpec
result = Math.min(result, specSize);
}
}
Log.i(TAG, "(" + mTag + ") measureHeight: result = " + result);
return result;
}
/**
* Render the text
*
* @see android.view.View#onDraw(android.graphics.Canvas)
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawText(mText, getPaddingLeft(), getPaddingTop() - mAscent, mTextPaint);
}
@Override
public void setX(float x) {
float x_center = x + getWidth() / 2;
super.setX(x_center);
super.setX(x_center);
}
@Override
public void setY(float y) {
float y_center = y - getHeight() / 2;
super.setY(y_center);
}
}
或PROMPT <sql>
的情况下回显输入sqlplus的命令可以这样做吗?
当前脚本:
@script.sql
当前输出:
$ cat test.sh
#!/bin/bash
LOG=/home/oracle/output.log
sqlplus hr/hr <<EOF > $LOG
set echo on
select 1 from dual;
QUIT
EOF`
我想要的是什么:
$ cat output.log
SQL*Plus: Release 11.2.0.4.0 Production on Tue Mar 1 15:01:12 2016
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> SQL>
1
----------
1
答案 0 :(得分:3)
当SQL * Plus从您的TTY读取命令时,输入的回显实际上由您的TTY处理,而不是SQL * Plus。如果SQL * Plus处理了回显,那么每次手动键入命令时,您都会看到命令两次(一次键入命令,一次回显)。
此外,TERMOUT
选项仅在运行脚本文件时适用,而不适用于从STDIN读取。
简单的解决方法是告诉SQL * Plus /dev/stdin
是一个脚本:
sqlplus scott/tiger @/dev/stdin <<EOF
SET TERMOUT ON ECHO ON
SELECT SYSDATE FROM dual;
EOF
答案 1 :(得分:1)
尝试spool
而不是重定向STDOUT:
#!/bin/bash
LOG=/home/oracle/output.log
sqlplus hr/hr <<EOF
set echo on term on
spool $LOG
select 1 from dual;
QUIT
EOF